Skip to content

Commit

Permalink
Fix static typing with Matplotlib 3.8 (#8030)
Browse files Browse the repository at this point in the history
* fix several typing issues with mpl3.8

* fix scatter plot typing and remove funky pyplot import

* fix some more typing errors

* fix some import errors

* undo some typing errors

* fix xylim typing

* add forgotten import

* ignore plotting overloads because None is Hashable

* add whats-new entry

* fix return type of hist

* fix another xylim type

* fix some more xylim types

* change to T_DataArray

* change accessor xylim to tuple

* add missing return types

* fix a typing error only on new mpl

* add unused-ignore to error codes for old mpl

* add more unused-ignore to error codes for old mpl

* replace type: ignore[attr-defined] with assert hasattr

* apply code review suggestions

---------

Co-authored-by: Illviljan <[email protected]>
  • Loading branch information
headtr1ck and Illviljan authored Sep 17, 2023
1 parent 45678bf commit babe9ff
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 242 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Breaking changes
extracts and add the indexes from another :py:class:`Coordinates` object
passed via ``coords`` (:pull:`8107`).
By `Benoît Bovy <https://github.com/benbovy>`_.
- Static typing of ``xlim`` and ``ylim`` arguments in plotting functions now must
be ``tuple[float, float]`` to align with matplotlib requirements. (:issue:`7802`, :pull:`8030`).
By `Michael Niklas <https://github.com/headtr1ck>`_.

Deprecations
~~~~~~~~~~~~
Expand Down
10 changes: 4 additions & 6 deletions xarray/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
from xarray.core.utils import FrozenDict

if TYPE_CHECKING:
try:
from matplotlib.colors import Colormap
except ImportError:
Colormap = str
from matplotlib.colors import Colormap

Options = Literal[
"arithmetic_join",
"cmap_divergent",
Expand Down Expand Up @@ -164,11 +162,11 @@ class set_options:
cmap_divergent : str or matplotlib.colors.Colormap, default: "RdBu_r"
Colormap to use for divergent data plots. If string, must be
matplotlib built-in colormap. Can also be a Colormap object
(e.g. mpl.cm.magma)
(e.g. mpl.colormaps["magma"])
cmap_sequential : str or matplotlib.colors.Colormap, default: "viridis"
Colormap to use for nondivergent data plots. If string, must be
matplotlib built-in colormap. Can also be a Colormap object
(e.g. mpl.cm.magma)
(e.g. mpl.colormaps["magma"])
display_expand_attrs : {"default", True, False}
Whether to expand the attributes section for display of
``DataArray`` or ``Dataset`` objects. Can be
Expand Down
Loading

0 comments on commit babe9ff

Please sign in to comment.