Closed
Description
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