Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-indexing doesn't preserve coord name for DataArray.to_dataframe calls #6356

Closed
gusostow opened this issue Mar 14, 2022 · 1 comment
Closed

Comments

@gusostow
Copy link

gusostow commented Mar 14, 2022

What happened?

Re-indexing doesn't preserve coord name for DataArray.to_dataframe calls. The resulting dataframe's index name is None.

What did you expect to happen?

In xarray 0.14 the name is preserved after reindex.

Minimal Complete Verifiable Example

import numpy as np
import xarray as xr

da = xr.DataArray(np.arange(5), dims=["a"], name="da", coords={"a": np.arange(5)})
print(da.to_dataframe().index.names)


print(da.reindex({"a": np.arange(5)}).to_dataframe().index.names)

Relevant log output

['a']
[None]

Anything else we need to know?

No response

Environment


/space/aostow/envs/xr2022/lib/python3.10/site-packages/_distutils_hack/__init__.py:30: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS
------------------
commit: None
python: 3.10.2 | packaged by conda-forge | (main, Mar  8 2022, 15:53:57) [GCC 9.4.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-1160.53.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: None
libnetcdf: None

xarray: 2022.3.0
pandas: 1.4.1
numpy: 1.22.3
scipy: None
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
setuptools: 60.9.3
pip: 22.0.4
conda: None
pytest: None
IPython: 8.0.1
sphinx: None

@gusostow gusostow added bug needs triage Issue that has not been reviewed by xarray team member labels Mar 14, 2022
@benbovy
Copy link
Member

benbovy commented Mar 21, 2022

Looks like it has been fixed in #5692. The main branch outputs:

['a']
['a']

@dcherian dcherian removed the needs triage Issue that has not been reviewed by xarray team member label Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants