diff --git a/Changelog b/Changelog index 46a5112a4..60e1b9f89 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ + since version 1.5.1.1 +============================== + * fix another slicing bug introduced by the fix to issue #906 (issue #922). + version 1.5.1.1 (tag v1.5.1.1rel) ================================== * fixed __version__ attribute (was set incorrectly in 1.5.1 release). diff --git a/netCDF4/utils.py b/netCDF4/utils.py index 261328c55..fea3a3c05 100644 --- a/netCDF4/utils.py +++ b/netCDF4/utils.py @@ -365,12 +365,14 @@ def _StartCountStride(elem, shape, dimensions=None, grp=None, datashape=None,\ datashape = broadcasted_shape(shape, datashape) # pad datashape with zeros for dimensions not being sliced (issue #906) - if datashape: + # only used when data covers slice over subset of dimensions + if datashape and len(datashape) != len(elem) and\ + len(datashape) == sum(1 for e in elem if type(e) == slice): datashapenew = (); i=0 for e in elem: - if type(e) != slice: + if type(e) != slice and not np.iterable(e): # scalar integer slice datashapenew = datashapenew + (0,) - else: + else: # slice object datashapenew = datashapenew + (datashape[i],) i+=1 datashape = datashapenew @@ -407,10 +409,13 @@ def _StartCountStride(elem, shape, dimensions=None, grp=None, datashape=None,\ if unlim and e.stop is not None and e.stop > shape[i]: length = e.stop elif unlim and e.stop is None and datashape != (): - if e.start is None: - length = datashape[i] - else: - length = e.start+datashape[i] + try: + if e.start is None: + length = datashape[i] + else: + length = e.start+datashape[i] + except IndexError: + raise IndexError("shape of data does not conform to slice") else: if unlim and datashape == () and len(dim) == 0: # writing scalar along unlimited dimension using slicing