home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 347558405

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
347558405 MDU6SXNzdWUzNDc1NTg0MDU= 2340 expand_dims erases named dim in the array's coordinates 90008 closed 0     5 2018-08-03T23:00:07Z 2018-08-05T01:15:49Z 2018-08-04T03:39:49Z CONTRIBUTOR      

Code Sample, a copy-pastable example if possible

```python

%%

import xarray as xa import numpy as np

n = np.zeros((3, 2))

data = xa.DataArray(n, dims=['y', 'x'], coords={'y':range(3), 'x':range(2)})

data = data.assign_coords(z=xa.DataArray(np.arange(6).reshape((3, 2)), dims=['y', 'x']))

print('Original Data') print('=============') print(data)

%%

my_slice = data[0, 1] print("Sliced data") print("===========") print("z coordinate remembers it's own x value") print(f'x = {my_slice.z.x}')

%%

expanded_slice = data[0, 1].expand_dims('x') print("expanded slice") print("==============") print("forgot that 'z' had 'x' coordinates") print("but remembered it had a 'y' coordinate") print(f"z = {expanded_slice.z}") print(expanded_slice.z.x) ```

Output: Original Data ============= <xarray.DataArray (y: 3, x: 2)> array([[0., 0.], [0., 0.], [0., 0.]]) Coordinates: * y (y) int32 0 1 2 * x (x) int32 0 1 z (y, x) int32 0 1 2 3 4 5 Sliced data =========== z coordinate remembers it's own x value x = <xarray.DataArray 'x' ()> array(1) Coordinates: y int32 0 x int32 1 z int32 1 expanded slice ============== forgot that 'z' had 'x' coordinates but remembered it had a 'y' coordinate z = <xarray.DataArray 'z' ()> array(1) Coordinates: y int32 0 z int32 1 AttributeError: 'DataArray' object has no attribute 'x'

Problem description

The coordinate used to have an explicit dimension. When we expanded the dimension, that information should not be erased. Note that information about other coordinates are maintained.

The challenge

The coordinates probably have fewer dimensions than the original data. I'm not sure about xarray's model, but a few challenges come to mind: 1. is the relative order of dimensions maintained between data in the same dataset/dataarray? 2. Can coordinates have MORE dimensions than the array itself?

The answer to these two questions might make or break If not, then this becomes a very difficult problem to solve since we don't know where to insert this new dimension in the coordinate array.

Output of xr.show_versions()

xa.show_versions() INSTALLED VERSIONS ------------------ commit: None python: 3.6.6.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 79 Stepping 1, GenuineIntel byteorder: little LC_ALL: None LANG: en LOCALE: None.None xarray: 0.10.7 pandas: 0.23.1 numpy: 1.14.3 scipy: 1.1.0 netCDF4: 1.4.0 h5netcdf: 0.6.1 h5py: 2.8.0 Nio: None zarr: None bottleneck: 1.2.1 cyordereddict: None dask: 0.18.1 distributed: 1.22.0 matplotlib: 2.2.2 cartopy: None seaborn: None setuptools: 39.2.0 pip: 9.0.3 conda: None pytest: 3.7.1 IPython: 6.4.0 sphinx: 1.7.5
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/2340/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 0 rows from issues_id in issues_labels
  • 5 rows from issue in issue_comments
Powered by Datasette · Queries took 0.765ms · About: xarray-datasette