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

xr.concat adds an extra array around elements #6384

Closed
Illviljan opened this issue Mar 20, 2022 · 1 comment · Fixed by #6385
Closed

xr.concat adds an extra array around elements #6384

Illviljan opened this issue Mar 20, 2022 · 1 comment · Fixed by #6385
Labels
bug needs triage Issue that has not been reviewed by xarray team member topic-indexing

Comments

@Illviljan
Copy link
Contributor

Illviljan commented Mar 20, 2022

What happened?

When concatenating dataarrays with pd.Interval along a dim the pd.Interval is wrapped with a numpy array and appended instead of without like it it was before #5692.

Minimal Complete Verifiable Example

import numpy as np
import xarray as xr

shape = (2, 3, 4)
darray = xr.DataArray(np.linspace(0, 1, num=np.prod(shape)).reshape(shape))
bins = [-1, 0, 1, 2]
a = darray.groupby_bins("dim_0", bins).mean(...)
a_nan = np.nan * a.isel(**{"dim_0_bins": -1})
out = xr.concat([a, a_nan], dim="dim_0_bins")
print(out["dim_0_bins"])

Relevant log output

Current result:

<xarray.DataArray 'dim_0_bins' (dim_0_bins: 4)>
array([Interval(-1, 0, closed='right'), Interval(0, 1, closed='right'),
       Interval(1, 2, closed='right'),
       array(Interval(1, 2, closed='right'), dtype=object)], dtype=object)
Coordinates:
  * dim_0_bins  (dim_0_bins) object (-1, 0] (0, 1] (1, 2] (1, 2]

Should be:

<xarray.DataArray 'dim_0_bins' (dim_0_bins: 4)>
array([Interval(-1, 0, closed='right'), Interval(0, 1, closed='right'),
       Interval(1, 2, closed='right'), Interval(1, 2, closed='right')],
      dtype=object)
Coordinates:
  * dim_0_bins  (dim_0_bins) object (-1, 0] (0, 1] (1, 2] (1, 2]

Anything else we need to know?

No response

Environment

xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.9.6 | packaged by conda-forge | (default, Jul 11 2021, 03:37:25) [MSC v.1916 64 bit (AMD64)]
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 58 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: en
LOCALE: ('Swedish_Sweden', '1252')
libhdf5: 1.10.6
libnetcdf: 4.7.4

xarray: 0.16.3.dev99+gc19467fb
pandas: 1.3.1
numpy: 1.21.5
scipy: 1.7.1
netCDF4: 1.5.6
pydap: installed
h5netcdf: 0.11.0
h5py: 2.10.0
Nio: None
zarr: 2.8.3
cftime: 1.5.0
nc_time_axis: 1.3.1
PseudoNetCDF: installed
rasterio: 1.2.6
cfgrib: None
iris: 3.0.4
bottleneck: 1.3.2
dask: 2021.10.0
distributed: 2021.10.0
matplotlib: 3.4.3
cartopy: 0.19.0.post1
seaborn: 0.11.1
numbagg: 0.2.1
fsspec: 2021.11.1
cupy: None
pint: 0.17
sparse: 0.12.0
setuptools: 49.6.0.post20210108
pip: 21.2.4
conda: None
pytest: 6.2.4
IPython: 7.31.0
sphinx: 4.3.2

@Illviljan Illviljan added bug needs triage Issue that has not been reviewed by xarray team member labels Mar 20, 2022
@Illviljan Illviljan changed the title xr.concat adds an extra array around object elements xr.concat adds an extra array around elements Mar 20, 2022
@benbovy
Copy link
Member

benbovy commented Mar 20, 2022

Thanks for reporting this issue @Illviljan. This should be fixed in #6385.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs triage Issue that has not been reviewed by xarray team member topic-indexing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants