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

numerical values for time (instead of datetime objects) are erroneously converted #33

Open
aportagain opened this issue Aug 11, 2023 · 0 comments
Labels

Comments

@aportagain
Copy link
Member

Numerical values for time (instead of datetime objects) are erroneously converted. We should probably either only accept datetime objects, or for numerical values preserve the units. The example currently in README.md even shows this in action:

In [1]: import json
   ...: import pprint as pp
   ...: import xarray as xr
   ...: from cfjson.xrdataset import CFJSONinterface
   ...: dset = xr.Dataset(data_vars={'hmo': ('time', [0.5, 0.6, 0.7])}, coords={'time': [1, 2, 3]})
   ...: dset['hmo'].attrs = {'standard_name': 'sea_surface_wave_significant_height', 'units': 'm'}
   ...: dset['time'].attrs = {'standard_name': 'time', 'units': 'days since 2020-01-01'}

In [2]: pp.pprint(json.loads(dset.cfjson.json_dumps()))
{'attributes': {},
 'dimensions': {'time': 3},
 'variables': {'hmo': {'attributes': {'standard_name': 'sea_surface_wave_significant_height',
                                      'units': 'm'},
                       'data': [0.5, 0.6, 0.7],
                       'shape': ['time']},
               'time': {'attributes': {'units': 'ISO8601 timestamps'},
                        'data': ['1970-01-01T00:00:00Z',
                                 '1970-01-01T00:00:00Z',
                                 '1970-01-01T00:00:00Z'],
                        'shape': ['time']}}}

In [3]:
@aportagain aportagain added the bug label Aug 11, 2023
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