Skip to content

Commit d6b815e

Browse files
authored
Merge pull request #1409 from Unidata/issue1408
allow non-unitary strides when slicing vlen vars (issue #1408)
2 parents 08b36ad + 8170fcf commit d6b815e

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
perform a membership operation on a Dataset (issue #1383)
77
* fix type hint for createEnumType (issue #1378)
88
* add python 3.13 to windows wheel builds (PR #1377)
9+
* allow slicing of vlen and string variables with non-unitary strides (issue #1408).
910

1011
version 1.7.2 (tag v1.7.2rel)
1112
=============================

src/netCDF4/_netCDF4.pyx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5966,10 +5966,9 @@ NC_CHAR).
59665966
ierr = nc_put_vara(self._grpid, self._varid,
59675967
startp, countp, strdata)
59685968
else:
5969-
raise IndexError('strides must all be 1 for string variables')
5970-
#with nogil:
5971-
# ierr = nc_put_vars(self._grpid, self._varid,
5972-
# startp, countp, stridep, strdata)
5969+
with nogil:
5970+
ierr = nc_put_vars(self._grpid, self._varid,
5971+
startp, countp, stridep, strdata)
59735972
_ensure_nc_success(ierr)
59745973
free(strdata)
59755974
else:
@@ -5995,10 +5994,9 @@ NC_CHAR).
59955994
ierr = nc_put_vara(self._grpid, self._varid,
59965995
startp, countp, vldata)
59975996
else:
5998-
raise IndexError('strides must all be 1 for vlen variables')
5999-
#with nogil:
6000-
# ierr = nc_put_vars(self._grpid, self._varid,
6001-
# startp, countp, stridep, vldata)
5997+
with nogil:
5998+
ierr = nc_put_vars(self._grpid, self._varid,
5999+
startp, countp, stridep, vldata)
60026000
_ensure_nc_success(ierr)
60036001
# free the pointer array.
60046002
free(vldata)
@@ -6091,11 +6089,9 @@ NC_CHAR).
60916089
ierr = nc_get_vara(self._grpid, self._varid,
60926090
startp, countp, strdata)
60936091
else:
6094-
# FIXME: is this a bug in netCDF4?
6095-
raise IndexError('strides must all be 1 for string variables')
6096-
#with nogil:
6097-
# ierr = nc_get_vars(self._grpid, self._varid,
6098-
# startp, countp, stridep, strdata)
6092+
with nogil:
6093+
ierr = nc_get_vars(self._grpid, self._varid,
6094+
startp, countp, stridep, strdata)
60996095
if ierr == NC_EINVALCOORDS:
61006096
raise IndexError
61016097
elif ierr != NC_NOERR:
@@ -6130,10 +6126,9 @@ NC_CHAR).
61306126
ierr = nc_get_vara(self._grpid, self._varid,
61316127
startp, countp, vldata)
61326128
else:
6133-
raise IndexError('strides must all be 1 for vlen variables')
6134-
#with nogil:
6135-
# ierr = nc_get_vars(self._grpid, self._varid,
6136-
# startp, countp, stridep, vldata)
6129+
with nogil:
6130+
ierr = nc_get_vars(self._grpid, self._varid,
6131+
startp, countp, stridep, vldata)
61376132
if ierr == NC_EINVALCOORDS:
61386133
raise IndexError
61396134
elif ierr != NC_NOERR:

test/test_vlen.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ def runTest(self):
7676
assert_array_equal(data2[j,i], data[j,i])
7777
assert datas[j,i] == data2s[j,i]
7878
assert_array_equal(datas, vs_alt[:])
79+
# issue #1408
80+
data2a = data2[::2,::2]
81+
data2b = v[::2,::2]
82+
data2sa = data2s[::2,::2]
83+
data2sb = vs[::2,::2]
84+
for i in range(nlons//2):
85+
for j in range(nlats//2):
86+
assert_array_equal(data2a[j,i], data2b[j,i])
87+
assert_array_equal(data2sa[j,i], data2sb[j,i])
7988
f.close()
8089

8190

0 commit comments

Comments
 (0)