Skip to content

TYP: towards matplotlib 3.8 #55253

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

Merged
merged 16 commits into from
Nov 15, 2023
Merged

TYP: towards matplotlib 3.8 #55253

merged 16 commits into from
Nov 15, 2023

Conversation

twoertwein
Copy link
Member

Type changes for matplotlib 3.8. There is more work needed:

  • failing CI with 3.8 CI: Pin matplotlib < 3.8 #55210 (comment)
  • refactor the use of matplotlib to not set non-existing attributes matploblib object and to avoid using private methods (see mypy errors below). This can be done in a separate PR (or we add type ignores for now).

Typing errors left with 3.8:

pandas/plotting/_matplotlib/timeseries.py:127: error: "Axes" has no attribute "_plot_data"; maybe "plot_date"?  [attr-defined]
pandas/plotting/_matplotlib/timeseries.py:139: error: "Axes" has no attribute "_plot_data"; maybe "plot_date"?  [attr-defined]
pandas/plotting/_matplotlib/timeseries.py:156: error: "Axes" has no attribute "_plot_data"; maybe "plot_date"?  [attr-defined]
pandas/plotting/_matplotlib/timeseries.py:158: error: "Axes" has no attribute "freq"  [attr-defined]
pandas/plotting/_matplotlib/timeseries.py:160: error: "XAxis" has no attribute "freq"  [attr-defined]
pandas/plotting/_matplotlib/timeseries.py:162: error: "Axes" has no attribute "legendlabels"  [attr-defined]
pandas/plotting/_matplotlib/timeseries.py:165: error: "Axes" has no attribute "view_interval"  [attr-defined]
pandas/plotting/_matplotlib/timeseries.py:166: error: "Axes" has no attribute "date_axis_info"  [attr-defined]
pandas/plotting/_matplotlib/core.py:468: error: "Axes" has no attribute "containers"  [attr-defined]
pandas/plotting/_matplotlib/core.py:485: error: "_AxesBase" has no attribute "_get_lines"; maybe "get_lines"?  [attr-defined]
pandas/plotting/_matplotlib/core.py:485: error: "Axes" has no attribute "_get_lines"  [attr-defined]
pandas/plotting/_matplotlib/core.py:486: error: "_AxesBase" has no attribute "_get_patches_for_fill"  [attr-defined]
pandas/plotting/_matplotlib/core.py:486: error: "Axes" has no attribute "_get_patches_for_fill"  [attr-defined]
pandas/plotting/_matplotlib/core.py:487: error: "Axes" has no attribute "right_ax"  [attr-defined]
pandas/plotting/_matplotlib/core.py:487: error: "_AxesBase" has no attribute "left_ax"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1440: error: "Axes" has no attribute "_plot_data"; maybe "plot_date"?  [attr-defined]
pandas/plotting/_matplotlib/core.py:1444: error: "Axes" has no attribute "freq"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1458: error: "Axes" has no attribute "_stacker_pos_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1460: error: "Axes" has no attribute "_stacker_neg_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1461: error: "Axes" has no attribute "_stacker_pos_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1462: error: "Axes" has no attribute "_stacker_neg_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1473: error: "Axes" has no attribute "_stacker_pos_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1475: error: "Axes" has no attribute "_stacker_neg_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1488: error: "Axes" has no attribute "_stacker_pos_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1490: error: "Axes" has no attribute "_stacker_neg_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1590: error: "Axes" has no attribute "_stacker_pos_prior"  [attr-defined]
pandas/plotting/_matplotlib/core.py:1592: error: "Axes" has no attribute "_stacker_neg_prior"  [attr-defined]

This PR will obviously fail as it doesn't update matplotlib itself.

@twoertwein twoertwein mentioned this pull request Sep 22, 2023
5 tasks
@mroeschke
Copy link
Member

refactor the use of matplotlib to not set non-existing attributes matploblib objec

xref #54485

@ksunden
Copy link

ksunden commented Sep 23, 2023

I have also opened matplotlib/matplotlib#26883, FYI, which fixes up some of them that we could do better on (not all, particularly I may do a followup regarding the None | Axis | _DummyAxis | _AxisWrapper stuff, though I at least made self.set_axis(self.axis) typecheck as okay.

Not handling the None case is something we do ourselves, for the record.

@twoertwein
Copy link
Member Author

twoertwein commented Sep 23, 2023

For some reason this line

https://github.com/pandas-dev/pandas/blame/9e1096e8373bc99675fd1b3490cfb7cf26041395/doc/source/user_guide/visualization.rst#L747

breaks the doc-test with matplotlib 3.8

Sphinx parallel build error:
RuntimeError: Unexpected exception in /home/runner/work/pandas/pandas/doc/source/user_guide/visualization.rst line 747
Error: Process completed with exit code 2.

edit:

Seems like pyright has a few additional errors they are mostly because pyright doesn't special case hasattr.

@mroeschke mroeschke added Visualization plotting Typing type annotations, mypy/pyright type checking labels Sep 25, 2023
@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Oct 26, 2023
@mroeschke mroeschke removed the Stale label Nov 8, 2023
@twoertwein
Copy link
Member Author

Thank you @mroeschke for rebasing! I'm very busy until at least 11/29 - if you or someone else wants to take over this PR, feel free to!

I think this PR might not need all changes since matplotlib 3.8.1 released (see failing mypy/pyright tests).

@mroeschke mroeschke added this to the 2.2 milestone Nov 15, 2023
@mroeschke mroeschke marked this pull request as ready for review November 15, 2023 20:21
@mroeschke mroeschke self-requested a review as a code owner November 15, 2023 20:21
@mroeschke mroeschke merged commit d999aac into pandas-dev:main Nov 15, 2023
@mroeschke
Copy link
Member

Thanks @twoertwein and @ksunden

jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Nov 15, 2023
* TYP: towards matplotlib 3.8

* test 3.8

* ignore pyright errors

* merging error

* Conditional on import

* Disable parallel build to see docbuild error

* Some unnecessary ignores

* Add typing in test_sql

* type ignores

* Multiple ignores

* Uncomment

---------

Co-authored-by: Matthew Roeschke <[email protected]>
@twoertwein twoertwein deleted the matplotlib branch December 10, 2023 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typing type annotations, mypy/pyright type checking Visualization plotting
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants