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

NCDataset.from_json() breaks if a variable doesn't have the "type" attribute #2

Open
aportagain opened this issue Jan 15, 2018 · 0 comments
Assignees
Labels

Comments

@aportagain
Copy link
Member

aportagain commented Jan 15, 2018

NCDataset.from_json() breaks if a variable doesn't have the "type" attribute, but our current spec doesn't say that "type" is required in general, only to ensure reversible transformations. I talked to Dave about this and we decided that ideally we should make it work according to the current spec. But first for my specific use case, I'll probably open a separate issue for missing "type" support in the xrdataset.CFJSONinterface.json_dumps().

To reproduce:

from cfjson.ncdataset import NCDataset
nc = NCDataset('/tmp/foo.nc', 'w')
j = '\n{\n  "dimensions": {\n    "time": 1\n  },\n  "attributes": {},\n  "variables": {\n    "time": {\n      "attributes": {\n        "units": "ISO8601 timestamps"\n      },\n      "shape": [\n        "time"\n      ],\n      "data": [\n        "2017-01-01T00:00:00Z"\n      ]\n    },\n    "hs": {\n      "attributes": {},\n      "shape": [\n        "time"\n      ],\n      "data": [\n        3.058\n      \n      ]\n    }\n  }\n}\n'
nc.from_json(j)

returns this error:

Issue occured when inserting global attributes
Could not create variable time
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/source/cf-json/cfjson/ncdataset.py", line 147, in from_json
    self.createVariable(var, dico['variables'][var]['type'],
KeyError: 'type'
@aportagain aportagain self-assigned this Jan 15, 2018
@aportagain aportagain added the bug label Jan 15, 2018
@aportagain aportagain changed the title NCDataset.from_json() breaks if a variables doesn't have the "type" attribute NCDataset.from_json() breaks if a variable doesn't have the "type" attribute Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant