issue_comments: 1530056660
This data as json
html_url | issue_url | id | node_id | user | created_at | updated_at | author_association | body | reactions | performed_via_github_app | issue |
---|---|---|---|---|---|---|---|---|---|---|---|
https://github.com/pydata/xarray/issues/7790#issuecomment-1530056660 | https://api.github.com/repos/pydata/xarray/issues/7790 | 1530056660 | IC_kwDOAMm_X85bMs_U | 14983768 | 2023-05-01T18:37:47Z | 2023-05-01T18:39:21Z | NONE | Oops! Yes. You are right. I had some cross-wording on the variable names. So I started a new notebook. Unfortunately, I think you may have also gotten some wires crossed? You set the time fill value to 1900-01-01, but then use NaT in the actual array? Here is a fresh notebook with a stand-alone cell with everything that I think you were doing, but I'm not 100%. The fill value is still wrong when it gets read out, but it is at least different? The fill value is now set to the units for some reason. This seems like progress? ```python import numpy as np import xarray as xr import zarr Create a time array with one fill value, NaTtime = np.array([np.datetime64("NaT", "ns"), '2023-01-02 00:00:00.00000000'], dtype='M8[ns]') Create xarray with this fill valuexr_time_array = xr.DataArray(data=time,dims=['time'],name='time') xr_ds = xr.Dataset(dict(time=xr_time_array)) print("****") print("xarray created with NaT fill value") print("----------------------") print(xr_ds["time"]) Save as zarrlocation_with_units = "xarray_and_units.zarr" encoding = { "time":{"_FillValue":np.datetime64("NaT","ns"),"dtype":np.int64,"units":"nanoseconds since 1970-01-01"} } xr_ds.to_zarr(location_with_units,mode="w",encoding=encoding) Read it back out againxr_read = xr.open_zarr(location_with_units) print("****") print("xarray created read with NaT fill value") print("----------------------") print(xr_read["time"]) print(xr_read["time"].attrs) print(xr_read["time"].encoding) ``` ``` xarray created with NaT fill value<xarray.DataArray 'time' (time: 2)> array([ 'NaT', '2023-01-02T00:00:00.000000000'], dtype='datetime64[ns]') Coordinates: * time (time) datetime64[ns] NaT 2023-01-02 xarray created read with NaT fill value<xarray.DataArray 'time' (time: 2)> array(['1970-01-01T00:00:00.000000000', '2023-01-02T00:00:00.000000000'], dtype='datetime64[ns]') Coordinates: * time (time) datetime64[ns] 1970-01-01 2023-01-02 {} {'chunks': (2,), 'preferred_chunks': {'time': 2}, 'compressor': Blosc(cname='lz4', clevel=5, shuffle=SHUFFLE, blocksize=0), 'filters': None, '_FillValue': -9223372036854775808, 'units': 'nanoseconds since 1970-01-01', 'calendar': 'proleptic_gregorian', 'dtype': dtype('int64')} ``` |
{ "total_count": 0, "+1": 0, "-1": 0, "laugh": 0, "hooray": 0, "confused": 0, "heart": 0, "rocket": 0, "eyes": 0 } |
1685803922 |