Skip to content

Commit f7bd1d2

Browse files
authored
Merge pull request #924 from Unidata/issue922
fix for issue #922
2 parents 9747532 + 5004e70 commit f7bd1d2

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Diff for: Changelog

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
since version 1.5.1.1
2+
==============================
3+
* fix another slicing bug introduced by the fix to issue #906 (issue #922).
4+
15
version 1.5.1.1 (tag v1.5.1.1rel)
26
==================================
37
* fixed __version__ attribute (was set incorrectly in 1.5.1 release).

Diff for: netCDF4/utils.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,14 @@ def _StartCountStride(elem, shape, dimensions=None, grp=None, datashape=None,\
365365
datashape = broadcasted_shape(shape, datashape)
366366

367367
# pad datashape with zeros for dimensions not being sliced (issue #906)
368-
if datashape:
368+
# only used when data covers slice over subset of dimensions
369+
if datashape and len(datashape) != len(elem) and\
370+
len(datashape) == sum(1 for e in elem if type(e) == slice):
369371
datashapenew = (); i=0
370372
for e in elem:
371-
if type(e) != slice:
373+
if type(e) != slice and not np.iterable(e): # scalar integer slice
372374
datashapenew = datashapenew + (0,)
373-
else:
375+
else: # slice object
374376
datashapenew = datashapenew + (datashape[i],)
375377
i+=1
376378
datashape = datashapenew
@@ -407,10 +409,13 @@ def _StartCountStride(elem, shape, dimensions=None, grp=None, datashape=None,\
407409
if unlim and e.stop is not None and e.stop > shape[i]:
408410
length = e.stop
409411
elif unlim and e.stop is None and datashape != ():
410-
if e.start is None:
411-
length = datashape[i]
412-
else:
413-
length = e.start+datashape[i]
412+
try:
413+
if e.start is None:
414+
length = datashape[i]
415+
else:
416+
length = e.start+datashape[i]
417+
except IndexError:
418+
raise IndexError("shape of data does not conform to slice")
414419
else:
415420
if unlim and datashape == () and len(dim) == 0:
416421
# writing scalar along unlimited dimension using slicing

0 commit comments

Comments
 (0)