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

createVariable: KeyError: 't' (works with netCDF4) #72

Closed
nschloe opened this issue Mar 9, 2020 · 2 comments
Closed

createVariable: KeyError: 't' (works with netCDF4) #72

nschloe opened this issue Mar 9, 2020 · 2 comments

Comments

@nschloe
Copy link

nschloe commented Mar 9, 2020

MWE:

import h5netcdf.legacyapi as netCDF4
# import netCDF4  # works


with netCDF4.Dataset("out.e", "w") as rootgrp:
    rootgrp.createDimension("time_step", None)
    data = rootgrp.createVariable("time_whole", "f4", "time_step")
    data[:] = 0.0
Traceback (most recent call last):
  File "b.py", line 7, in <module>
    data = rootgrp.createVariable("time_whole", "f4", "time_step")
  File "/home/nschloe/.local/lib/python3.8/site-packages/h5netcdf/legacyapi.py", line 91, in createVariable
    return super(Group, self).create_variable(
  File "/home/nschloe/.local/lib/python3.8/site-packages/h5netcdf/core.py", line 500, in create_variable
    return group._create_child_variable(keys[-1], dimensions, dtype, data,
  File "/home/nschloe/.local/lib/python3.8/site-packages/h5netcdf/core.py", line 463, in _create_child_variable
    shape = tuple(self._current_dim_sizes[d] for d in dimensions)
  File "/home/nschloe/.local/lib/python3.8/site-packages/h5netcdf/core.py", line 463, in <genexpr>
    shape = tuple(self._current_dim_sizes[d] for d in dimensions)
  File "/usr/lib/python3.8/collections/__init__.py", line 891, in __getitem__
    return self.__missing__(key)            # support subclasses that define __missing__
  File "/usr/lib/python3.8/collections/__init__.py", line 883, in __missing__
    raise KeyError(key)
KeyError: 't'
@shoyer
Copy link
Collaborator

shoyer commented Mar 21, 2020

You’re setting dimensions=“time_step”. NetCDF4-Python apparently interprets this as a list of one string whereas h5netcdf interprets it as a sequence of characters.

I would argue that this is probably a programming error, and it would be best to require users to explicitly pass a list or tuple of strings.

If you or anyone else is interested, I would be happy to accept a pull request making this behavior raise TypeError.

@nschloe
Copy link
Author

nschloe commented Dec 18, 2020

I would argue that this is probably a programming error,

Agreed. netcdf should be stricter here.

@nschloe nschloe closed this as completed Dec 18, 2020
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