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

inconsistent dimension propagation in .interp() with non-numeric types #8099

Closed
4 tasks done
st-bender opened this issue Aug 22, 2023 · 0 comments · Fixed by #9887
Closed
4 tasks done

inconsistent dimension propagation in .interp() with non-numeric types #8099

st-bender opened this issue Aug 22, 2023 · 0 comments · Fixed by #9887

Comments

@st-bender
Copy link
Contributor

st-bender commented Aug 22, 2023

What happened?

Hi,
tried to find a similar issue, but haven't seen it.
When interpolating a dataset containing non-numeric types using a DataArray for the new coordinates, then the dimensions of the interpolated data set differ from the case with only numeric types.
Not sure this is clear enough, see the example.

Edit: looks like nothing is interpolated at all in the non-numeric case.

What did you expect to happen?

The output dimensions should be the same in both cases and match the ones of the numeric-only case.

Minimal Complete Verifiable Example

import xarray as xr
import numpy as np

ds = xr.Dataset(
    {"x": ("a", np.arange(4))},
    coords={"a": (np.arange(4) - 1.5)},
)

t = xr.DataArray(
    np.random.randn(6).reshape((2, 3)) * 0.5,
    dims=["r", "s"],
    coords={"r": np.arange(2) - 0.5, "s": np.arange(3) - 1},
)

ds["m"] = ds.x > 1

# different dimensions for `x`, compare
ds.interp(a=t, method="linear")

# to numeric only
ds[["x"]].interp(a=t, method="linear")

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.

Relevant log output

# Output in the numeric-only case:
<xarray.Dataset>
Dimensions:  (r: 2, s: 3)
Coordinates:
    a        (r, s) float64 -0.177 -0.2806 -0.1925 -0.1464 0.3165 0.6232
  * r        (r) float64 -0.5 0.5
  * s        (s) int64 -1 0 1
Data variables:
    x        (r, s) float64 1.323 1.219 1.308 1.354 1.816 2.123


# output including non-numeric variables:
<xarray.Dataset>
Dimensions:  (a: 4, r: 2, s: 3)
Coordinates:
  * a        (r, s) float64 -0.177 -0.2806 -0.1925 -0.1464 0.3165 0.6232
  * r        (r) float64 -0.5 0.5
  * s        (s) int64 -1 0 1
Data variables:
    x        (a) int64 0 1 2 3
    m        (a) bool False False True True

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0]
python-bits: 64
OS: Linux
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: C.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.2
libnetcdf: 4.9.1

xarray: 2023.7.0
pandas: 2.0.3
numpy: 1.25.2
scipy: 1.11.1
netCDF4: 1.6.3
pydap: installed
h5netcdf: 1.2.0
h5py: 3.8.0
Nio: None
zarr: 2.16.0
cftime: 1.6.2
nc_time_axis: None
PseudoNetCDF: None
iris: None
bottleneck: None
dask: 2023.8.0
distributed: 2023.8.0
matplotlib: 3.7.2
cartopy: 0.22.0
seaborn: None
numbagg: None
fsspec: 2023.6.0
cupy: None
pint: None
sparse: None
flox: 0.7.2
numpy_groupies: 0.9.22
setuptools: 68.0.0
pip: 23.2.1
conda: 23.7.2
pytest: 7.4.0
mypy: None
IPython: 8.7.0
sphinx: 5.3.0

@st-bender st-bender added bug needs triage Issue that has not been reviewed by xarray team member labels Aug 22, 2023
@dcherian dcherian removed the needs triage Issue that has not been reviewed by xarray team member label Nov 9, 2024
dcherian added a commit to dcherian/xarray that referenced this issue Dec 13, 2024
dcherian added a commit to dcherian/xarray that referenced this issue Dec 13, 2024
dcherian added a commit to dcherian/xarray that referenced this issue Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants