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

polyval doesn't bind the output type #7312

Closed
3 of 4 tasks
derhintze opened this issue Nov 23, 2022 · 3 comments · Fixed by #7315
Closed
3 of 4 tasks

polyval doesn't bind the output type #7312

derhintze opened this issue Nov 23, 2022 · 3 comments · Fixed by #7315

Comments

@derhintze
Copy link

What happened?

We recently updated our package requirements to current xarray, and while some typing things got better for us, xarray.polyval seems to not allow mypy to correctly infer its output type.

What did you expect to happen?

Output type should depend on the input types.

Minimal Complete Verifiable Example

from __future__ import annotations


import numpy as np
import xarray as xr

coeffs = xr.DataArray([1, 1])
xvals = xr.DataArray(np.arange(10))

result = xr.polyval(xvals, coeffs=coeffs)
reveal_type(result)

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

test.py:11: note: Revealed type is "Union[xarray.core.dataset.Dataset, xarray.core.dataarray.DataArray]"

Anything else we need to know?

No response

Environment

INSTALLED VERSIONS

commit: None
python: 3.9.10 (main, Mar 15 2022, 15:56:56)
[GCC 7.5.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-1160.49.1.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.12.2
libnetcdf: 4.9.0

xarray: 2022.11.0
pandas: 1.5.1
numpy: 1.23.5
scipy: 1.9.3
netCDF4: 1.6.2
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.6.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: 3.6.2
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: 65.6.0
pip: 22.3.1
conda: None
pytest: 7.2.0
IPython: 8.6.0
sphinx: None

@derhintze derhintze added bug needs triage Issue that has not been reviewed by xarray team member labels Nov 23, 2022
@derhintze
Copy link
Author

note that pylance says the same: Type of "result" is "Dataset | DataArray"

@headtr1ck headtr1ck added topic-typing and removed needs triage Issue that has not been reviewed by xarray team member labels Nov 23, 2022
@headtr1ck
Copy link
Collaborator

Weird, the overloads should capture that.
We have one for DataArray, DataArray -> DataArray.

Have to look into that, thanks for the report!

@headtr1ck headtr1ck mentioned this issue Nov 23, 2022
4 tasks
@headtr1ck
Copy link
Collaborator

Should be fixed in the next version. In the meantime, you can try explicitly adding a degree_dim="degree" argument, this should solve the issue.

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