home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 559841620

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
559841620 MDU6SXNzdWU1NTk4NDE2MjA= 3748 `swap_dims()` incorrectly changes underlying index name 4666753 closed 0     1 2020-02-04T16:41:25Z 2020-02-24T22:34:58Z 2020-02-24T22:34:58Z CONTRIBUTOR      

MCVE Code Sample

```python import xarray as xr

create data array with named dimension and named coordinate

x = xr.DataArray([1], {"idx": [2], "y": ("idx", [3])}, ["idx"], name="x")

what's our current index? (idx, this is fine)

x.indexes

prints "idx: Int64Index([2], dtype='int64', name='idx')"

swap dim so that y is our dimension, what's index now?

x.swap_dims({"idx": "y"}).indexes

prints "y: Int64Index([3], dtype='int64', name='idx')"

``` The dimension name is appropriately swapped but the pandas index name is incorrect.

Expected Output

```python

swap dim so that y is our dimension, what's index now?

x.swap_dims({"idx": "y"}).indexes

prints "y: Int64Index([3], dtype='int64', name='y')"

```

Problem Description

This is a problem because running x.swap_dims({"idx": "y"}).to_dataframe() gives a dataframe with columns ["x", "idx"] and index "idx". This gives ambiguous names and drops the original name, while the DataArray string representation gives no indication that this might be happening.

Output of xr.show_versions()

# Paste the output here xr.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.8.1 | packaged by conda-forge | (default, Jan 29 2020, 15:06:10) [Clang 9.0.1 ] python-bits: 64 OS: Darwin OS-release: 18.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.5 libnetcdf: 4.7.3 xarray: 0.15.0 pandas: 0.25.3 numpy: 1.18.1 scipy: 1.4.1 netCDF4: 1.5.3 pydap: None h5netcdf: None h5py: 2.10.0 Nio: None zarr: None cftime: 1.0.4.2 nc_time_axis: None PseudoNetCDF: None rasterio: None cfgrib: None iris: None bottleneck: None dask: 2.10.1 distributed: 2.10.0 matplotlib: None cartopy: None seaborn: None numbagg: None setuptools: 45.1.0.post20200119 pip: 20.0.2 conda: None pytest: 5.3.5 IPython: 7.12.0 sphinx: None
{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3748/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

  • 1 row from issues_id in issues_labels
  • 1 row from issue in issue_comments
Powered by Datasette · Queries took 6.7ms · About: xarray-datasette