Skip to content

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

@aportagain

Description

@aportagain

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]:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions