8000 Adaptions for Matplotlib 3.6 by trexfeathers · Pull Request #4998 · SciTools/iris · GitHub
[go: up one dir, main page]

Skip to content

Adaptions for Matplotlib 3.6 #4998

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 6 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions benchmarks/benchmarks/import_iris.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,30 @@
# licensing details.
from importlib import import_module, reload

################
# Prepare info for reset_colormaps:

# Import and capture colormaps.
from matplotlib import colormaps # isort:skip

_COLORMAPS_ORIG = set(colormaps)

# Import iris.palette, which modifies colormaps.
import iris.palette

# Derive which colormaps have been added by iris.palette.
_COLORMAPS_MOD = set(colormaps)
COLORMAPS_EXTRA = _COLORMAPS_MOD - _COLORMAPS_ORIG

# Touch iris.palette to prevent linters complaining.
_ = iris.palette

################


class Iris:
@staticmethod
def _import(module_name):
def _import(module_name, reset_colormaps=False):
"""
Have experimented with adding sleep() commands into the imported
modules. The results reveal:
Expand All @@ -25,6 +45,13 @@ def _import(module_name):
and the repetitions are therefore no faster than the first run.
"""
mod = import_module(module_name)

if reset_colormaps:
# Needed because reload() will attempt to register new colormaps a
# second time, which errors by default.
for cm_name in COLORMAPS_EXTRA:
colormaps.unregister(cm_name)

reload(mod)

def time_iris(self):
Expand Down Expand Up @@ -205,7 +232,7 @@ def time_iterate(self):
self._import("iris.iterate")

def time_palette(self):
self._import("iris.palette")
self._import("iris.palette", reset_colormaps=True)

def time_plot(self):
self._import("iris.plot")
Expand Down
9 changes: 9 additions & 0 deletions docs/src/whatsnew/latest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,20 @@ This document explains the changes made to Iris for this release

#. `@rcomer`_ introduced the ``dask >=2.26`` minimum pin, so that Iris can benefit
from Dask's support for `NEP13`_ and `NEP18`_. (:pull:`4905`)

#. `@trexfeathers`_ advanced the Cartopy pin to ``>=0.21``, as Cartopy's
change to default Transverse Mercator projection affects an Iris test.
See `SciTools/cartopy@fcb784d`_ and `SciTools/cartopy@8860a81`_ for more
details.
(:pull:`4968`)

#. `@trexfeathers`_ introduced the ``netcdf4!=1.6.1`` pin to avoid a problem
with segfaults. (:pull:`4968`)

#. `@trexfeathers`_ updated the Matplotlib colormap registration in
:mod:`iris.palette` in response to a deprecation warning. Using the new
Matplotlib API also means a ``matplotlib>=3.5`` pin. (:pull:`4998`)


📚 Documentation
================
Expand All @@ -114,6 +120,9 @@ This document explains the changes made to Iris for this release
:mod:`~iris.fileformats.netcdf.loader` and :mod:`~iris.fileformats.netcdf.saver`
submodules, just to make the code easier to handle.

#. `@trexfeathers`_ adapted the benchmark for importing :mod:`iris.palette` to
cope with new colormap behaviour in Matplotlib `v3.6`. (:pull:`4998`)


.. comment
Whatsnew author names (@github name) in alphabetical order. Note that,
Expand Down
3 changes: 2 additions & 1 deletion lib/iris/palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import re

import cf_units
from matplotlib import colormaps as mpl_colormaps
import matplotlib.cm as mpl_cm
import matplotlib.colors as mpl_colors
import numpy as np
Expand Down Expand Up @@ -337,7 +338,7 @@ def _load_palette():
)

# Register the color map for use.
mpl_cm.register_cmap(cmap=cmap)
mpl_colormaps.register(cmap)


# Ensure to load the color map palettes.
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci/py310.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- cf-units >=3.1
- cftime >=1.5
- dask-core >=2.26
- matplotlib
- matplotlib >=3.5
- netcdf4 !=1.6.1
- numpy >=1.19
- python-xxhash
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci/py38.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- cf-units >=3.1
- cftime >=1.5
- dask-core >=2.26
- matplotlib
- matplotlib >=3.5
- netcdf4 !=1.6.1
- numpy >=1.19
- python-xxhash
Expand Down
2 changes: 1 addition & 1 deletion requirements/ci/py39.yml
67F4
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- cf-units >=3.1
- cftime >=1.5
- dask-core >=2.26
- matplotlib
- matplotlib >=3.5
- netcdf4 !=1.6.1
- numpy >=1.19
- python-xxhash
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ install_requires =
cf-units>=3.1
cftime>=1.5.0
dask[array]>=2.26
matplotlib
matplotlib>=3.5
netcdf4!=1.6.1
numpy>=1.19
scipy
Expand Down
0