Skip to content

xr.concat adds an extra array around elements #6384

Closed
@Illviljan

Description

@Illviljan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions