home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 592191561

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/3785#issuecomment-592191561 https://api.github.com/repos/pydata/xarray/issues/3785 592191561 MDEyOklzc3VlQ29tbWVudDU5MjE5MTU2MQ== 11326731 2020-02-27T21:42:54Z 2020-02-27T22:41:48Z NONE

@ngreenwald you need to update your version of xarray to 0.12.2 or greater and use the load_dataarray method instead of the open_dataarray one, in which case, the cache option is not necessary. More info here: http://xarray.pydata.org/en/stable/generated/xarray.load_dataarray.html

Here your example corrected, showing the expected output:

```python import xarray as xr import numpy as np import os

create two different xarrays with different sizes and coords

test_xr1 = xr.DataArray(np.zeros((5, 5, 3)), coords=[range(5), range(5), ["x1", "y1", "z1"]], dims=["1", "2", "3"]) test_xr2 = xr.DataArray(np.zeros((10, 2, 3)), coords=[range(10), range(2), ["x2", "y2", "z2"]], dims=["1", "2", "3"])

display(test_xr1.coords) display(test_xr2.coords) Out: Coordinates: * 1 (1) int64 0 1 2 3 4 * 2 (2) int64 0 1 2 3 4 * 3 (3) <U2 'x1' 'y1' 'z1'

Coordinates: * 1 (1) int64 0 1 2 3 4 5 6 7 8 9 * 2 (2) int64 0 1 * 3 (3) <U2 'x2' 'y2' 'z2' python

save first xarray, reload it, and inspect coords

test_xr1.to_netcdf("test_xr.xr") loaded_xr = xr.load_dataarray("test_xr.xr") loaded_xr.coords Out: Coordinates: * 1 (1) int64 0 1 2 3 4 * 2 (2) int64 0 1 2 3 4 * 3 (3) object 'x1' 'y1' 'z1' python

remove first xarray, save second with the same name, and load it

os.remove("test_xr.xr") test_xr2.to_netcdf("test_xr.xr") loaded_xr = xr.load_dataarray("test_xr.xr") loaded_xr.coords Out: Coordinates: * 1 (1) int64 0 1 2 3 4 5 6 7 8 9 * 2 (2) int64 0 1 * 3 (3) object 'x2' 'y2' 'z2' ```

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