home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 358570582

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/1064#issuecomment-358570582 https://api.github.com/repos/pydata/xarray/issues/1064 358570582 MDEyOklzc3VlQ29tbWVudDM1ODU3MDU4Mg== 1997005 2018-01-18T08:16:06Z 2018-01-18T08:16:06Z CONTRIBUTOR

There you go !

```python import numpy import pandas import tempfile import warnings import xarray

array1 = xarray.DataArray( numpy.random.rand(5), dims=['time'], coords={'time': pandas.to_datetime(['2018-01-01', '2018-01-01 00:01', '2018-01-01 00:02', '2018-01-01 00:03', '2018-01-01 00:04'])}, name='foo' )

array2 = xarray.DataArray( numpy.random.rand(5), dims=['time'], coords={'time': pandas.to_datetime(['2018-01-01 00:05', '2018-01-01 00:05:10', '2018-01-01 00:05:20', '2018-01-01 00:05:30', '2018-01-01 00:05:40'])}, name='foo' )

with tempfile.NamedTemporaryFile() as tmp: # save first array array1.to_netcdf(tmp.name) # reload it array1_reloaded = xarray.open_dataarray(tmp.name)

# the time encoding stores minutes as int, so seconds won't be allowed at next call of to_netcdf
assert array1_reloaded.time.encoding['dtype'] == numpy.int64
assert array1_reloaded.time.encoding['units'] == 'minutes since 2018-01-01 00:00:00'

merged = xarray.merge([array1_reloaded, array2])
array1_reloaded.close()

with warnings.catch_warnings():
    warnings.filterwarnings('error', category=RuntimeWarning)
    merged.to_netcdf(tmp.name)

```

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  185709414
Powered by Datasette · Queries took 0.633ms · About: xarray-datasette