pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.56k stars 1.07k forks source link

Bug in dateconversion? #1195

Closed jbusecke closed 7 years ago

jbusecke commented 7 years ago

I noticed an undesired behavior in xarray when using xarray.open_dataset:

running the following in version 0.8.2-90-g2c7730d:

import xarray as xr
fid = 'dt_global_allsat_msla_uv_20140101_20140829.nc'
ds = xr.open_dataset(fid)
ds.time

gives

<xarray.DataArray 'time' (time: 1)>
array(['2013-12-31T19:00:00.000000000-0500'], dtype='datetime64[ns]')
Coordinates:
  * time     (time) datetime64[ns] 2014-01-01
Attributes:
    long_name: Time
    standard_name: time
    axis: T

Note the hour is 19, I also encountered files with 20. Since the time in the .nc file is given in 'days since', the expected output would be 00.

Indeed when running version 0.8.2 the output is:

<xarray.DataArray 'time' (time: 1)>
array(['2014-01-01T00:00:00.000000000'], dtype='datetime64[ns]')
Coordinates:
  * time     (time) datetime64[ns] 2014-01-01
Attributes:
    long_name: Time
    standard_name: time
    axis: T

Any idea what could cause this?

Sample file used in the example can be found here: https://ufile.io/077da

fmaussion commented 7 years ago

I can't reproduce this. Which numpy version do you have installed? (see https://docs.scipy.org/doc/numpy-dev/reference/arrays.datetime.html#changes-with-numpy-1-11)

shoyer commented 7 years ago

I'm pretty sure this is indeed a timezone display issue fixed by NumPy 1.11.

jhamman commented 7 years ago

Agreed: https://github.com/pydata/xarray/issues/439

jbusecke commented 7 years ago

Fantastic! Thanks very much.