Skip to content

Inserting data into variable with unlimited dimension with slice(n, n+1, None) is broken #922

Closed
@cpaulik

Description

@cpaulik

Another side effect of #906 it seems

import netCDF4
import numpy as np

with netCDF4.Dataset('test.nc','w') as f:
    f.createDimension('d1',3)
    f.createDimension('d2',None)

    f.createVariable('v1',np.float,('d1','d1',))
    f['v1'][0:1] = np.arange(3)

Running this on 1.5.1.1 gives

1.5.1.1
(0, 3)
Traceback (most recent call last):
  File "01-160948.py", line 23, in <module>
    f['v1'][0:1] = np.arange(3)
  File "netCDF4/_netCDF4.pyx", line 4796, in netCDF4._netCDF4.Variable.__setitem__
  File "/home/cpa/.pyenv/versions/miniconda2-4.3.30/envs/pytesmo/lib/python3.7/site-packages/netCDF4/utils.py", line 374, in _StartCountStride
    datashapenew = datashapenew + (datashape[i],)
IndexError: tuple index out of range

on 1.5.0.1 it works and gives

1.5.0.1
(0, 3)
(1, 3)

The following is also broken so it is not only for the first element:

import netCDF4
import numpy as np

with netCDF4.Dataset('test.nc','w') as f:
    f.createDimension('d1',3)
    f.createDimension('d2',None)

    f.createVariable('v1',np.float,('d2','d1'))
    print(f['v1'].shape)
    f['v1'][0] = np.arange(3)
    print(f['v1'].shape)
    f['v1'][1:2] = np.arange(3)
    print(f['v1'].shape)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions