You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to save a xr.Dataset that was created from a pandas dataframe with tz-aware time index ( see #3291) - xarray converts the time index into a int64 nanosecs
For example, this is what the converted dataset looks like:
<xarray.Dataset>
Dimensions: (symbol: 3196, time: 4977)
Coordinates:
* time (time) object 946933200000000000 ... 1566334800000000000
* symbol (symbol) int64 0 1 2 3 4 5 6 ... 3189 3190 3191 3192 3193 3194 3195
Data variables:
var_0 (time, symbol) float32 nan 4301510000.0 nan nan ... nan nan nan nan
var_1 (time, symbol) object nan False nan nan nan ... nan nan nan nan nan
var_2 (time, symbol) float32 nan 475.0 nan nan nan ... nan nan nan nan
var_3 (time, symbol) float32 nan 475.0 nan nan nan ... nan nan nan nan
var_5 (time, symbol) float32 nan 475.9 nan nan nan ... nan nan nan nan
var_6 (time, symbol) float32 nan 475.9 nan nan nan ... nan nan nan nan
var_7 (time, symbol) float32 nan 429.5 nan nan nan ... nan nan nan nan
var_8 (time, symbol) float32 nan 429.5 nan nan nan ... nan nan nan nan
var_10 (time, symbol) float32 nan -0.06736842 nan nan ... nan nan nan nan
var_11 (time, symbol) float32 nan 0.05085102 nan nan ... nan nan nan nan
var_12 (time, symbol) float32 nan 0.029103609 nan nan ... nan nan nan nan
var_13 (time, symbol) float32 nan 0.048769474 nan nan ... nan nan nan nan
var_14 (time, symbol) float32 nan 442.9 nan nan nan ... nan nan nan nan
var_15 (time, symbol) float32 nan 442.9 nan nan nan ... nan nan nan nan
var_16 (time, symbol) float32 nan nan nan nan nan ... nan nan nan nan nan
var_17 (time, symbol) float32 nan nan nan nan nan ... nan nan nan nan nan
var_18 (time, symbol) float32 nan nan nan nan nan ... nan nan nan nan nan
var_19 (time, symbol) float32 nan nan nan nan nan ... nan nan nan nan nan
var_20 (time, symbol) float32 nan nan nan nan nan ... nan nan nan nan nan
var_21 (time, symbol) float32 nan 9501900.0 nan nan ... nan nan nan nan
var_22 (time, symbol) float32 nan 9501900.0 nan nan ... nan nan nan nan
Now when I try to save this dataset using
pds.to_netcdf( ... )
I get the following error:
Dropping into pdb when this error is hit - it looks like the problem is with the time index.
After converting the time index into a regular int index by:
andersy005
changed the title
Error saving xr.Dataset to netcdf format.
Error saving xr.Dataset with timezone aware time index to netcdf format.
Jan 17, 2022
Just a ping on this, was wondering if this ever got resolved. I still cannot assign tz-aware datetime64ns-dtype objects as the time coordinate variable.
When I try to save a xr.Dataset that was created from a pandas dataframe with tz-aware time index ( see #3291) - xarray converts the time index into a int64 nanosecs
For example, this is what the converted dataset looks like:
Now when I try to save this dataset using
I get the following error:

Dropping into pdb when this error is hit - it looks like the problem is with the time index.
After converting the time index into a regular int index by:
this works OK.
And this also works !!
Note
pd.to_datetime(pds.time)
drops the timezone from the index - so the issue is very much about saving tz-aware time indices.Any ideas on what I can do about this ?
Thanks!
-firdaus
The text was updated successfully, but these errors were encountered: