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

Indexing a vlen variable produces inconsistent results #1306

Closed
5tefan opened this issue Jan 9, 2024 · 1 comment
Closed

Indexing a vlen variable produces inconsistent results #1306

5tefan opened this issue Jan 9, 2024 · 1 comment

Comments

@5tefan
Copy link

5tefan commented Jan 9, 2024

Summary

Indexing a vlen variable produces inconsistent results:

import netCDF4 as nc
import numpy as np

nc_out = nc.Dataset("ex.nc", "w", diskless=True, persist=False)
t = nc_out.createDimension("t", None)
v = nc_out.createVariable("s", str, ("t",))

v[0] = "aaa"
v[1] = "bbb"
v[2] = "ccc"
v[3] = "ddd"

print("1. ", v[:])
print("2. ", v[np.arange(4)])
print("3. ", v[np.array([0, 1, 2])])
print("4. ", v[np.array([0, 3, 2])])

Produces the following output:

1.  ['aaa' 'bbb' 'ccc' 'ddd']
2.  ['aaa' 'bbb' 'ccc' 'ddd']
3.  ['aaa' 'bbb' 'ccc']
4.  [array('aaa', dtype=object) array('ddd', dtype=object)
 array('ccc', dtype=object)]

The result of number 4 is surprising and seems to be a bug. Items 1, 2, and 3 show expected behavior. The issue occurs when indexing out of order.

Versions

  1. MacOS Ventura 13.6.3 Intel based
  2. Reproduced with Python v3.10.13 and 3.8.10.
  3. netcdf4 Python versions 1.6.5 and 1.5.7
jswhit added a commit that referenced this issue Jan 22, 2024
@jswhit
Copy link
Collaborator

jswhit commented Jan 22, 2024

closed by PR #1309

@jswhit jswhit closed this as completed Jan 22, 2024
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

2 participants