diff --git a/Changelog b/Changelog index 46a5112..315c40c 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ + version 1.5.1.2 (tag v1.5.1.2rel) +================================== + * 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/README.md b/README.md index 0e6d989..896bd8f 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,10 @@ ## News For details on the latest updates, see the [Changelog](https://github.com/Unidata/netcdf4-python/blob/master/Changelog). -05/02/2019: Version [1.5.1.1](https://pypi.python.org/pypi/netCDF4/1.5.1.1) released. Fixes incorrect __version__ +05/06/2019: Version [1.5.1.2](https://pypi.python.org/pypi/netCDF4/1.5.1.2) released. Fixes another slicing +slicing regression ([issue #922)](https://github.com/Unidata/netcdf4-python/issues/922)) introduced in the 1.5.1 release. + +05/02/2019: Version [1.5.1.1](https://pypi.python.org/pypi/netCDF4/1.5.1.1) released. Fixes incorrect `__version__` module variable in 1.5.1 release, plus a slicing bug ([issue #919)](https://github.com/Unidata/netcdf4-python/issues/919)). 04/30/2019: Version [1.5.1](https://pypi.python.org/pypi/netCDF4/1.5.1) released. Bugfixes, no new features. diff --git a/docs/netCDF4/index.html b/docs/netCDF4/index.html index 77815cd..0daff66 100644 --- a/docs/netCDF4/index.html +++ b/docs/netCDF4/index.html @@ -4,7 +4,7 @@ netCDF4 API documentation -

netCDF4 module

-

Version 1.5.1.1

+

Version 1.5.1.2


Introduction

netcdf4-python is a Python interface to the netCDF C library.

diff --git a/netCDF4/_netCDF4.pyx b/netCDF4/_netCDF4.pyx index def2a73..6238b8c 100644 --- a/netCDF4/_netCDF4.pyx +++ b/netCDF4/_netCDF4.pyx @@ -1,5 +1,5 @@ """ -Version 1.5.1.1 +Version 1.5.1.2 --------------- - - - @@ -1190,7 +1190,7 @@ # python3: zip is already python2's itertools.izip pass -__version__ = "1.5.1.1" +__version__ = "1.5.1.2" # Initialize numpy import posixpath diff --git a/netCDF4/utils.py b/netCDF4/utils.py index 261328c..fea3a3c 100644 --- a/netCDF4/utils.py +++ b/netCDF4/utils.py @@ -365,12 +365,14 @@ 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 @@ 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 diff --git a/setup.py b/setup.py index 02e3a96..c2a76da 100644 --- a/setup.py +++ b/setup.py @@ -584,7 +584,7 @@ setup(name="netCDF4", cmdclass=cmdclass, - version="1.5.1.1", + version="1.5.1.2", long_description="netCDF version 4 has many features not found in earlier versions of the library, such as hierarchical groups, zlib compression, multiple unlimited dimensions, and new data types. It is implemented on top of HDF5. This module implements most of the new features, and can read and write netCDF files compatible with older versions of the library. The API is modelled after Scientific.IO.NetCDF, and should be familiar to users of that module.\n\nThis project is hosted on a `GitHub repository `_ where you may access the most up-to-date source.", author="Jeff Whitaker", author_email="jeffrey.s.whitaker@noaa.gov", diff --git a/test/tst_slicing.py b/test/tst_slicing.py index 66f5901..1e06b32 100644 --- a/test/tst_slicing.py +++ b/test/tst_slicing.py @@ -235,5 +235,19 @@ f['v1'][:] = arr assert_array_equal(f['v1'][:],np.broadcast_to(arr,f['v1'].shape)) + def test_issue922(self): + with Dataset(self.file,'w') as f: + f.createDimension('d1',3) + f.createDimension('d2',None) + f.createVariable('v1',np.int,('d2','d1',)) + f['v1'][0] = np.arange(3,dtype=np.int) + f['v1'][1:3] = np.arange(3,dtype=np.int) + assert_array_equal(f['v1'][:], np.broadcast_to(np.arange(3),(3,3))) + f.createVariable('v2',np.int,('d1','d2',)) + f['v2'][:,0] = np.arange(3,dtype=np.int) + f['v2'][:,1:3] = np.arange(6,dtype=np.int).reshape(3,2) + assert_array_equal(f['v2'][:,1:3],np.arange(6,dtype=np.int).reshape(3,2)) + assert_array_equal(f['v2'][:,0],np.arange(3,dtype=np.int)) + if __name__ == '__main__': unittest.main()