Skip to content

Commit 7b2adc6

Browse files
Jeffrey WhitakerJeffrey Whitaker
authored andcommitted
allow non-unitary strides when slicing vlen vars
1 parent 08b36ad commit 7b2adc6

3 files changed

Lines changed: 19 additions & 12 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 & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5966,10 +5966,10 @@ 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+
#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)
59735973
_ensure_nc_success(ierr)
59745974
free(strdata)
59755975
else:
@@ -5995,10 +5995,10 @@ NC_CHAR).
59955995
ierr = nc_put_vara(self._grpid, self._varid,
59965996
startp, countp, vldata)
59975997
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)
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)
60026002
_ensure_nc_success(ierr)
60036003
# free the pointer array.
60046004
free(vldata)
@@ -6130,10 +6130,10 @@ NC_CHAR).
61306130
ierr = nc_get_vara(self._grpid, self._varid,
61316131
startp, countp, vldata)
61326132
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)
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)
61376137
if ierr == NC_EINVALCOORDS:
61386138
raise IndexError
61396139
elif ierr != NC_NOERR:

test/test_vlen.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ 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+
for i in range(nlons//2):
83+
for j in range(nlats//2):
84+
assert_array_equal(data2a[j,i], data2b[j,i])
7985
f.close()
8086

8187

0 commit comments

Comments
 (0)