issues: 545764524
This data as json
| id | node_id | number | title | user | state | locked | assignee | milestone | comments | created_at | updated_at | closed_at | author_association | active_lock_reason | draft | pull_request | body | reactions | performed_via_github_app | state_reason | repo | type |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 545764524 | MDU6SXNzdWU1NDU3NjQ1MjQ= | 3665 | Cannot roundtrip time in NETCDF4_CLASSIC | 10194086 | closed | 0 | 4 | 2020-01-06T14:47:48Z | 2020-01-16T18:27:15Z | 2020-01-16T18:27:14Z | MEMBER | MCVE Code Sample``` python import numpy as np import xarray as xr time = xr.cftime_range("2006-01-01", periods=2, calendar="360_day") da = xr.DataArray(time, dims=["time"]) da.encoding["dtype"] = np.float da.to_netcdf("tst.nc", format="NETCDF4_CLASSIC") ds = xr.open_dataset("tst.nc") ds.to_netcdf("tst2.nc", format="NETCDF4_CLASSIC") ``` yields:
Or an example without ```python import numpy as np import xarray as xr time = xr.cftime_range("2006-01-01", periods=2, calendar="360_day") da = xr.DataArray(time, dims=["time"]) da.encoding["_FillValue"] = np.array([np.nan]) xr.backends.netcdf3.encode_nc3_variable(xr.conventions.encode_cf_variable(da)) ``` Expected OutputXarray can save the dataset/ an Problem DescriptionIf there is a time variable that can be encoded using integers only, but that has a Note: if the time cannot be encoded using integers only, it works: ``` python da = xr.DataArray(time, dims=["time"]) da.encoding["_FillValue"] = np.array([np.nan]) da.encoding["units"] = "days since 2006-01-01T12:00:00" xr.backends.netcdf3.encode_nc3_variable(xr.conventions.encode_cf_variable(da)) ``` Another note: when saving with NETCDF4 ``` python da = xr.DataArray(time, dims=["time"]) da.encoding["_FillValue"] = np.array([np.nan]) xr.backends.netCDF4_._encode_nc4_variable(xr.conventions.encode_cf_variable(da))
Output of
|
{
"url": "https://api.github.com/repos/pydata/xarray/issues/3665/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
} |
completed | 13221727 | issue |