Skip to content

Commit

Permalink
MNT: migrate away from packaging.version.parse_version as its fallbac…
Browse files Browse the repository at this point in the history
…k mechanism is going away in a future version
  • Loading branch information
neutrinoceros committed Aug 31, 2021
1 parent bff9354 commit 84d3008
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions yt/funcs.py
Expand Up @@ -25,7 +25,7 @@
import matplotlib
import numpy as np
from more_itertools import always_iterable, collapse, first
from packaging.version import parse as parse_version
from packaging.version import Version
from tqdm import tqdm

from yt.units import YTArray, YTQuantity
Expand Down Expand Up @@ -1039,7 +1039,7 @@ def matplotlib_style_context(style_name=None, after_reset=False):
import matplotlib

style_name = {"mathtext.fontset": "cm"}
if parse_version(matplotlib.__version__) >= parse_version("3.3.0"):
if Version(matplotlib.__version__) >= Version("3.3.0"):
style_name["mathtext.fallback"] = "cm"
else:
style_name["mathtext.fallback_to_cm"] = True
Expand Down
4 changes: 2 additions & 2 deletions yt/utilities/on_demand_imports.py
@@ -1,6 +1,6 @@
import sys

from packaging.version import parse as parse_version
from packaging.version import Version


class NotAModule:
Expand Down Expand Up @@ -361,7 +361,7 @@ def __init__(self):
try:
import h5py

if parse_version(h5py.__version__) < parse_version("2.4.0"):
if Version(h5py.__version__) < Version("2.4.0"):
self._err = RuntimeError(
"yt requires h5py version 2.4.0 or newer, "
"please update h5py with e.g. `python -m pip install -U h5py` "
Expand Down
12 changes: 6 additions & 6 deletions yt/visualization/base_plot_types.py
Expand Up @@ -2,7 +2,7 @@

import matplotlib
import numpy as np
from packaging.version import parse as parse_version
from packaging.version import Version

from yt.funcs import (
get_brewer_cmap,
Expand Down Expand Up @@ -132,9 +132,9 @@ def save(self, name, mpl_kwargs=None, canvas=None):

if mpl_kwargs is None:
mpl_kwargs = {}
if "papertype" not in mpl_kwargs and parse_version(
matplotlib.__version__
) < parse_version("3.3.0"):
if "papertype" not in mpl_kwargs and Version(matplotlib.__version__) < Version(
"3.3.0"
):
mpl_kwargs["papertype"] = "auto"

name = validate_image_name(name)
Expand Down Expand Up @@ -218,8 +218,8 @@ def _init_image(self, data, cbnorm, cblinthresh, cmap, extent, aspect):
cblinthresh = np.nanmin(np.absolute(data)[data != 0])

cbnorm_kwargs.update(dict(linthresh=cblinthresh, vmin=vmin, vmax=vmax))
MPL_VERSION = parse_version(matplotlib.__version__)
if MPL_VERSION >= parse_version("3.2.0"):
MPL_VERSION = Version(matplotlib.__version__)
if MPL_VERSION >= Version("3.2.0"):
# note that this creates an inconsistency between mpl versions
# since the default value previous to mpl 3.4.0 is np.e
# but it is only exposed since 3.2.0
Expand Down
6 changes: 3 additions & 3 deletions yt/visualization/color_maps.py
@@ -1,10 +1,10 @@
import numpy as np
from matplotlib import __version__ as mpl_ver, cm as mcm, colors as cc
from packaging.version import parse as parse_version
from packaging.version import Version

from . import _colormap_data as _cm

MPL_VERSION = parse_version(mpl_ver)
MPL_VERSION = Version(mpl_ver)
del mpl_ver


Expand Down Expand Up @@ -260,7 +260,7 @@ def show_colormaps(subset="all", filename=None):
"to be 'all', 'yt_native', or a list of "
"valid colormap names."
) from e
if parse_version("2.0.0") <= MPL_VERSION < parse_version("2.2.0"):
if Version("2.0.0") <= MPL_VERSION < Version("2.2.0"):
# the reason we do this filtering is to avoid spurious warnings in CI when
# testing against old versions of matplotlib (currently not older than 2.0.x)
# and we can't easily filter warnings at the level of the relevant test itself
Expand Down
6 changes: 3 additions & 3 deletions yt/visualization/plot_window.py
Expand Up @@ -7,7 +7,7 @@
import numpy as np
from more_itertools import always_iterable
from mpl_toolkits.axes_grid1 import ImageGrid
from packaging.version import parse as parse_version
from packaging.version import Version
from unyt.exceptions import UnitConversionError

from yt._maintenance.deprecation import issue_deprecation_warning
Expand Down Expand Up @@ -63,7 +63,7 @@ def zip_equal(*args):
return zip(*args, strict=True)


MPL_VERSION = parse_version(matplotlib.__version__)
MPL_VERSION = Version(matplotlib.__version__)

# Some magic for dealing with pyparsing being included or not
# included in matplotlib (not in gentoo, yes in everything else)
Expand Down Expand Up @@ -1202,7 +1202,7 @@ def _setup_plots(self):
self.plots[f].cax.yaxis.set_ticks(mticks, minor=True)

elif self._field_transform[f] == log_transform:
if MPL_VERSION >= parse_version("3.0.0"):
if MPL_VERSION >= Version("3.0.0"):
self.plots[f].cax.minorticks_on()
self.plots[f].cax.xaxis.set_visible(False)
else:
Expand Down
6 changes: 3 additions & 3 deletions yt/visualization/profile_plotter.py
Expand Up @@ -7,7 +7,7 @@
import matplotlib
import numpy as np
from more_itertools.more import always_iterable, unzip
from packaging.version import parse as parse_version
from packaging.version import Version

from yt.data_objects.profiles import create_profile, sanitize_field_tuple_keys
from yt.data_objects.static_output import Dataset
Expand All @@ -28,7 +28,7 @@
validate_plot,
)

MPL_VERSION = parse_version(matplotlib.__version__)
MPL_VERSION = Version(matplotlib.__version__)


def invalidate_profile(f):
Expand Down Expand Up @@ -1174,7 +1174,7 @@ def _setup_plots(self):
if self._cbar_minorticks[f]:
if self._field_transform[f] == linear_transform:
self.plots[f].cax.minorticks_on()
elif MPL_VERSION < parse_version("3.0.0"):
elif MPL_VERSION < Version("3.0.0"):
# before matplotlib 3 log-scaled colorbars internally used
# a linear scale going from zero to one and did not draw
# minor ticks. Since we want minor ticks, calculate
Expand Down

0 comments on commit 84d3008

Please sign in to comment.