Skip to content

Commit ce75202

Browse files
matthewturkmeeseeksmachine
authored andcommitted
Backport PR yt-project#3494: MNT: migrate away from packaging.version.parse
1 parent 71699c4 commit ce75202

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

yt/funcs.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import matplotlib
2626
import numpy as np
2727
from more_itertools import always_iterable, collapse, first
28-
from packaging.version import parse as parse_version
28+
from packaging.version import Version
2929
from tqdm import tqdm
3030

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

10411041
style_name = {"mathtext.fontset": "cm"}
1042-
if parse_version(matplotlib.__version__) >= parse_version("3.3.0"):
1042+
if Version(matplotlib.__version__) >= Version("3.3.0"):
10431043
style_name["mathtext.fallback"] = "cm"
10441044
else:
10451045
style_name["mathtext.fallback_to_cm"] = True

yt/utilities/on_demand_imports.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22

3-
from packaging.version import parse as parse_version
3+
from packaging.version import Version
44

55

66
class NotAModule:
@@ -361,7 +361,7 @@ def __init__(self):
361361
try:
362362
import h5py
363363

364-
if parse_version(h5py.__version__) < parse_version("2.4.0"):
364+
if Version(h5py.__version__) < Version("2.4.0"):
365365
self._err = RuntimeError(
366366
"yt requires h5py version 2.4.0 or newer, "
367367
"please update h5py with e.g. `python -m pip install -U h5py` "

yt/visualization/base_plot_types.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import matplotlib
44
import numpy as np
5-
from packaging.version import parse as parse_version
5+
from packaging.version import Version
66

77
from yt.funcs import (
88
get_brewer_cmap,
@@ -132,9 +132,9 @@ def save(self, name, mpl_kwargs=None, canvas=None):
132132

133133
if mpl_kwargs is None:
134134
mpl_kwargs = {}
135-
if "papertype" not in mpl_kwargs and parse_version(
136-
matplotlib.__version__
137-
) < parse_version("3.3.0"):
135+
if "papertype" not in mpl_kwargs and Version(matplotlib.__version__) < Version(
136+
"3.3.0"
137+
):
138138
mpl_kwargs["papertype"] = "auto"
139139

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

220220
cbnorm_kwargs.update(dict(linthresh=cblinthresh, vmin=vmin, vmax=vmax))
221-
MPL_VERSION = parse_version(matplotlib.__version__)
222-
if MPL_VERSION >= parse_version("3.2.0"):
221+
MPL_VERSION = Version(matplotlib.__version__)
222+
if MPL_VERSION >= Version("3.2.0"):
223223
# note that this creates an inconsistency between mpl versions
224224
# since the default value previous to mpl 3.4.0 is np.e
225225
# but it is only exposed since 3.2.0

yt/visualization/color_maps.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import numpy as np
22
from matplotlib import __version__ as mpl_ver, cm as mcm, colors as cc
3-
from packaging.version import parse as parse_version
3+
from packaging.version import Version
44

55
from . import _colormap_data as _cm
66

7-
MPL_VERSION = parse_version(mpl_ver)
7+
MPL_VERSION = Version(mpl_ver)
88
del mpl_ver
99

1010

@@ -260,7 +260,7 @@ def show_colormaps(subset="all", filename=None):
260260
"to be 'all', 'yt_native', or a list of "
261261
"valid colormap names."
262262
) from e
263-
if parse_version("2.0.0") <= MPL_VERSION < parse_version("2.2.0"):
263+
if Version("2.0.0") <= MPL_VERSION < Version("2.2.0"):
264264
# the reason we do this filtering is to avoid spurious warnings in CI when
265265
# testing against old versions of matplotlib (currently not older than 2.0.x)
266266
# and we can't easily filter warnings at the level of the relevant test itself

yt/visualization/plot_window.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import numpy as np
88
from more_itertools import always_iterable
99
from mpl_toolkits.axes_grid1 import ImageGrid
10-
from packaging.version import Version, parse as parse_version
10+
from packaging.version import Version
1111
from unyt.exceptions import UnitConversionError
1212

1313
from yt._maintenance.deprecation import issue_deprecation_warning
@@ -64,7 +64,7 @@ def zip_equal(*args):
6464
return zip(*args, strict=True)
6565

6666

67-
MPL_VERSION = parse_version(matplotlib.__version__)
67+
MPL_VERSION = Version(matplotlib.__version__)
6868

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

12111211
elif self._field_transform[f] == log_transform:
1212-
if MPL_VERSION >= parse_version("3.0.0"):
1212+
if MPL_VERSION >= Version("3.0.0"):
12131213
self.plots[f].cax.minorticks_on()
12141214
self.plots[f].cax.xaxis.set_visible(False)
12151215
else:

yt/visualization/profile_plotter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import numpy as np
99
from matplotlib.font_manager import FontProperties
1010
from more_itertools.more import always_iterable, unzip
11-
from packaging.version import parse as parse_version
11+
from packaging.version import Version
1212

1313
from yt.data_objects.profiles import create_profile, sanitize_field_tuple_keys
1414
from yt.data_objects.static_output import Dataset
@@ -30,7 +30,7 @@
3030
validate_plot,
3131
)
3232

33-
MPL_VERSION = parse_version(matplotlib.__version__)
33+
MPL_VERSION = Version(matplotlib.__version__)
3434

3535

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

0 commit comments

Comments
 (0)