Skip to content

Plot accessors miss static typing #6949

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

Closed
4 tasks done
headtr1ck opened this issue Aug 23, 2022 · 0 comments · Fixed by #7052
Closed
4 tasks done

Plot accessors miss static typing #6949

headtr1ck opened this issue Aug 23, 2022 · 0 comments · Fixed by #7052

Comments

@headtr1ck
Copy link
Collaborator

What happened?

The plot accessors i.e. dataarray.plot of type _PlotMethods are missing static typing especially of function attributes. See #6947 for an example.

The problem is that many plotting methods are added using hooks via decorators, something that mypy does not understand.

What did you expect to happen?

As a quick fix: type the plot accessors as _PlotMethods | Any to avoid false positives in mypy.

Better to either restructure the accessor with static methods instead of hooks or figure out another way of telling static type checkers about these methods.

Anyway: mypy should not complain.

Minimal Complete Verifiable Example

import xarray as xr

da = xr.DataArray([[1,2,3], [4,5,6]], dims=["x", "y"])
da.plot.contourf(x="x", y="y")
# mypy complains:
# error: "_PlotMethods" has no attribute "contourf"

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

No response

Anything else we need to know?

No response

Environment

On mobile, can edit it later if required.
Newest xarray should have this problem, before the accessor was Any.

@headtr1ck headtr1ck added bug needs triage Issue that has not been reviewed by xarray team member labels Aug 23, 2022
@dcherian dcherian added topic-typing and removed needs triage Issue that has not been reviewed by xarray team member labels Aug 24, 2022
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