Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 2d numpy array to 3d variable with first dimension of length 1 has changed behavior #919

Closed
cpaulik opened this issue May 1, 2019 · 5 comments

Comments

@cpaulik
Copy link
Contributor

cpaulik commented May 1, 2019

In version 1.5.1 the following code errors:

We are assigning a shape (100, 100) array to a (1, 100, 100) variable.
Not sure if this is supposed to work but it did in the past.

import netCDF4
import numpy as np

with netCDF4.Dataset('test.nc','w') as f:
    f.createDimension('time',1)
    f.createDimension('lat',100)
    f.createDimension('lon',100)

    f.createVariable('v1',np.float,('time', 'lon','lat',))
    arr = np.arange(100*100).reshape((100, 100))
    f['v1'][:] = arr
  File "01-160948.py", line 11, in <module>
    f['v1'][:] = arr
  File "netCDF4/_netCDF4.pyx", line 4796, in netCDF4._netCDF4.Variable.__setitem__
  File "/home/cpa/.pyenv/versions/miniconda2-4.3.30/envs/libsat/lib/python3.6/site-packages/netCDF4/utils.py", line 352, in _StartCountStride
    datashapenew = datashapenew + (datashape[i],)
IndexError: tuple index out of range

It works up to version 1.5.0.1

@cpaulik cpaulik changed the title Assignment of variable where 1 dimension is of length 1 has changed behavior Assignment 2d numpy array to 3d variable with first dimension of length 1 has changed behavior May 1, 2019
@akrherz
Copy link

akrherz commented May 1, 2019

same here, example works on 1.5.0.1, fails on 1.5.1

@jswhit
Copy link
Collaborator

jswhit commented May 1, 2019

Probably a side effect of the fix for #906

@jswhit
Copy link
Collaborator

jswhit commented May 1, 2019

Potential fix in pull request #920 (branch issue919). Also fixes issue #918.

@jswhit
Copy link
Collaborator

jswhit commented May 2, 2019

Going to merge this now and make a new release later today. Please reopen if problems persist.

@jswhit jswhit closed this as completed May 2, 2019
jswhit added a commit that referenced this issue May 2, 2019
@cpaulik
Copy link
Contributor Author

cpaulik commented May 3, 2019

thank you for the quick fix. Will test in the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants