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/2636#issuecomment-450458650,https://api.github.com/repos/pydata/xarray/issues/2636,450458650,MDEyOklzc3VlQ29tbWVudDQ1MDQ1ODY1MA==,30388627,2018-12-29T02:38:00Z,2018-12-29T02:39:41Z,NONE,"@dcherian It works by `netCDF4`, but not for `xarray`: ``` file = Dataset('ds1.nc') print (file.variables['time'],'\n') with xr.open_dataset('ds1.nc') as f: print (f.time.attrs) ``` Output: ``` int64 time(time) units: hours since 2015-01-01 unlimited dimensions: current shape = (3,) filling on, default _FillValue of -9223372036854775806 used OrderedDict() ``` What's the difference between `units` and `attrs`?","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,394625579 https://github.com/pydata/xarray/issues/2636#issuecomment-450457809,https://api.github.com/repos/pydata/xarray/issues/2636,450457809,MDEyOklzc3VlQ29tbWVudDQ1MDQ1NzgwOQ==,2448579,2018-12-29T02:28:53Z,2018-12-29T02:28:53Z,MEMBER,"The values of your `time` variable are preserved but the `units` change. I wonder if we should consider this a round-tripping bug. ``` python attrs = {'units': 'hours since 2015-01-01'} ds_1 = xr.Dataset({'temperature': (['x', 'y', 'time'], temp)}, coords={'lon': (['x', 'y'], lon), 'lat': (['x', 'y'], lat), 'time': ('time', [100, 101, 102], attrs)}) print(ds_1.time.attrs) ds_1.to_netcdf('ds1.nc') file = xr.open_dataset('ds1.nc') print(file.time.attrs) file.close() ``` gives output ``` OrderedDict([('units', 'hours since 2015-01-01')]) OrderedDict() ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,394625579 https://github.com/pydata/xarray/issues/2636#issuecomment-450456616,https://api.github.com/repos/pydata/xarray/issues/2636,450456616,MDEyOklzc3VlQ29tbWVudDQ1MDQ1NjYxNg==,30388627,2018-12-29T02:17:49Z,2018-12-29T02:17:49Z,NONE,"@xylar Thanks! I just found [another question](https://stackoverflow.com/questions/46702600/how-to-prevent-xarray-from-converting-time-offsets-to-absolute-datetimes) similar to this one. I've tried some operations: ``` with xr.open_dataset('merge.nc') as f: print (f['temperature'],'\n') print ('---------------------------') print (f.mean(dim='time')) print ('---------------------------') print (f['temperature'].loc[:,:,'2015-01-05T04:00:00',]) print ('---------------------------') ``` It works fine: ``` array([[[-0.022611, -1.428088, -0.655508, 0.977389, -0.428088, 0.344492], [ 0.430102, 0.996973, -0.882054, 1.430102, 1.996973, 0.117946]], [[ 0.157233, -0.230397, -0.505775, 1.157233, 0.769603, 0.494225], [-0.075826, -1.933904, -0.823982, 0.924174, -0.933904, 0.176018]]]) Coordinates: lon (x, y) float64 ... lat (x, y) float64 ... * time (time) datetime64[ns] 2015-01-05T04:00:00 2015-01-05T05:00:00 ... Dimensions without coordinates: x, y --------------------------- Dimensions: (x: 2, y: 2) Coordinates: lon (x, y) float64 ... lat (x, y) float64 ... Dimensions without coordinates: x, y Data variables: temperature (x, y) float64 -0.2021 0.6817 0.307 -0.4446 --------------------------- array([[-0.022611, 0.430102], [ 0.157233, -0.075826]]) Coordinates: lon (x, y) float64 ... lat (x, y) float64 ... time datetime64[ns] 2015-01-05T04:00:00 Dimensions without coordinates: x, y --------------------------- ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,394625579 https://github.com/pydata/xarray/issues/2636#issuecomment-450455452,https://api.github.com/repos/pydata/xarray/issues/2636,450455452,MDEyOklzc3VlQ29tbWVudDQ1MDQ1NTQ1Mg==,4179064,2018-12-29T02:07:54Z,2018-12-29T02:07:54Z,NONE,"@zxdawn, I was able to verify that, by adding `decode_times=False` to your code, I get: ``` keys of merge: odict_keys(['lon', 'lat', 'temperature', 'time']) time of merge: int64 time(time) units: hours since 2015-01-01 unlimited dimensions: current shape = (6,) filling on, default _FillValue of -9223372036854775806 used ```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,394625579 https://github.com/pydata/xarray/issues/2636#issuecomment-450400275,https://api.github.com/repos/pydata/xarray/issues/2636,450400275,MDEyOklzc3VlQ29tbWVudDQ1MDQwMDI3NQ==,4179064,2018-12-28T17:54:19Z,2018-12-28T17:54:19Z,NONE,"Depending on your needs, you might be able to get away with calling `open_mfdataset` with `decode_times=False`. This should leave your `time` coordinate as it is (i.e. integer hours since 2015-01-01) but that will limit the types of operations you can do on the `time` dimension because it will not be converted to some kind of `DateTime` object. For example, it would be difficult to do time averaging that is aware of months, years, etc.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,394625579 https://github.com/pydata/xarray/issues/2636#issuecomment-450382495,https://api.github.com/repos/pydata/xarray/issues/2636,450382495,MDEyOklzc3VlQ29tbWVudDQ1MDM4MjQ5NQ==,2448579,2018-12-28T16:03:23Z,2018-12-28T16:03:23Z,MEMBER,"I have never tried this but try setting those units as encoding, not attrs. ","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",,394625579