-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Interpolation always returns floats #4770
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
Comments
#4771 forces the dtype to |
IMO if someone wants this they should just use |
Using nearest works if all variables are integers. # 100x more variables in actual dataset:
ds = xr.Dataset(
{
"numeric": ("time", 1.0 + np.arange(0, 4, 1)),
"non_numeric_integer": ("time", np.array([1, 2, 3, 4], dtype=np.int8)),
"non_numeric": ("time", np.array(["a", "b", "c", "d"])),
},
coords={"time": (np.arange(0, 4, 1))},
)
actual = ds.interp(time=np.linspace(0, 3, 7))
expected = xr.Dataset(
{
"numeric": ("time", 1 + np.linspace(0, 3, 7)),
"non_numeric_integer": ("time", np.array([1, 2, 2, 3, 3, 4, 4], dtype=np.int8)),
"non_numeric": ("time", np.array(["a", "b", "b", "c", "c", "d", "d"])),
},
coords={"time": np.linspace(0, 3, 7)},
)
xr.testing.assert_identical(actual, expected) We could make it optional what data types are considered Lines 4198 to 4205 in 755581c
|
What happened:
When interpolating datasets integer arrays are forced to floats.
What you expected to happen:
To retain the same dtype after interpolation.
Minimal Complete Verifiable Example:
Anything else we need to know?:
An easy first step is to also force
np.float_
inda.blockwise
inmissing.interp_func
.The more difficult way is to somehow be able to change back the dataarrays into the old dtype without affecting performance. I did a test simply adding
.astype()
to the returned value inmissing.interp
and it doubled the calculation time.I was thinking the conversion to floats in scipy could be avoided altogether by adding a (non-)public option to ignore any dtype checks and just let the user handle the "unsafe" interpolations.
Related:
scipy/scipy#11093
Environment:
Output of xr.show_versions()
xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
python-bits: 64
OS: Windows
libhdf5: 1.10.4
libnetcdf: None
xarray: 0.16.2
pandas: 1.1.5
numpy: 1.17.5
scipy: 1.4.1
netCDF4: None
pydap: None
h5netcdf: None
h5py: 2.10.0
Nio: None
zarr: None
cftime: None
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.2
dask: 2020.12.0
distributed: 2020.12.0
matplotlib: 3.3.2
cartopy: None
seaborn: 0.11.1
numbagg: None
pint: None
setuptools: 51.0.0.post20201207
pip: 20.3.3
conda: 4.9.2
pytest: 6.2.1
IPython: 7.19.0
sphinx: 3.4.0
The text was updated successfully, but these errors were encountered: