diff --git a/.github/workflows/bleeding-edge.yaml b/.github/workflows/bleeding-edge.yaml index c932b7ee7f0..bfb19d0e62f 100644 --- a/.github/workflows/bleeding-edge.yaml +++ b/.github/workflows/bleeding-edge.yaml @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v3 - name: Set up Python (newest testable version) - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: # the '-dev' suffix allows to use alphas and betas if no final release is available yet # this version should be upgraded as often as possible, typically once a year when numpy diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 86ae8ec7fee..084b2c4cb70 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -67,7 +67,7 @@ jobs: steps: - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Checkout repo (bare) diff --git a/.github/workflows/type-checking.yaml b/.github/workflows/type-checking.yaml index 578516b4b45..97b760aa7b1 100644 --- a/.github/workflows/type-checking.yaml +++ b/.github/workflows/type-checking.yaml @@ -28,7 +28,7 @@ jobs: fetch-depth: 0 - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: '3.7' diff --git a/.github/workflows/wheels.yaml b/.github/workflows/wheels.yaml index afb4ff8939c..3b484e5d15c 100644 --- a/.github/workflows/wheels.yaml +++ b/.github/workflows/wheels.yaml @@ -71,7 +71,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v3 - name: Set up Python - uses: actions/setup-python@v3 + uses: actions/setup-python@v4 with: python-version: '3.10' - name: install check-manifest diff --git a/doc/source/cookbook/multiplot_2x2.py b/doc/source/cookbook/multiplot_2x2.py index 7580dc3918c..0bda1081894 100644 --- a/doc/source/cookbook/multiplot_2x2.py +++ b/doc/source/cookbook/multiplot_2x2.py @@ -53,6 +53,6 @@ plot.cax = grid.cbar_axes[i] # Finally, redraw the plot on the AxesGrid axes. -p._setup_plots() +p.render() plt.savefig("multiplot_2x2.png") diff --git a/doc/source/cookbook/multiplot_2x2_coordaxes_slice.py b/doc/source/cookbook/multiplot_2x2_coordaxes_slice.py index f13547d2f71..3998c6d0f3d 100644 --- a/doc/source/cookbook/multiplot_2x2_coordaxes_slice.py +++ b/doc/source/cookbook/multiplot_2x2_coordaxes_slice.py @@ -55,6 +55,6 @@ plot.cax = grid.cbar_axes[1] # Finally, redraw the plot. - p._setup_plots() + p.render() plt.savefig("multiplot_2x2_coordaxes_slice.png") diff --git a/doc/source/cookbook/multiplot_2x2_time_series.py b/doc/source/cookbook/multiplot_2x2_time_series.py index 7be73311f4e..bdbc7baa62a 100644 --- a/doc/source/cookbook/multiplot_2x2_time_series.py +++ b/doc/source/cookbook/multiplot_2x2_time_series.py @@ -45,6 +45,6 @@ plot.cax = grid.cbar_axes[i] # Finally, this actually redraws the plot. - p._setup_plots() + p.render() plt.savefig("multiplot_2x2_time_series.png") diff --git a/doc/source/cookbook/multiplot_phaseplot.py b/doc/source/cookbook/multiplot_phaseplot.py index 28f074d35d8..db6d244e6c5 100644 --- a/doc/source/cookbook/multiplot_phaseplot.py +++ b/doc/source/cookbook/multiplot_phaseplot.py @@ -47,9 +47,9 @@ plot.cax = grid.cbar_axes[i] # Actually redraws the plot. - p._setup_plots() + p.render() - # Modify the axes properties **after** p._setup_plots() so that they + # Modify the axes properties **after** p.render() so that they # are not overwritten. plot.axes.xaxis.set_minor_locator(plt.LogLocator(base=10.0, subs=[2.0, 5.0, 8.0])) diff --git a/yt/frontends/flash/data_structures.py b/yt/frontends/flash/data_structures.py index 2362610a66d..7685083dd86 100644 --- a/yt/frontends/flash/data_structures.py +++ b/yt/frontends/flash/data_structures.py @@ -400,7 +400,7 @@ def _parse_parameter_file(self): dle = np.array([self.parameters[f"{ax}min"] for ax in "xyz"]).astype("float64") dre = np.array([self.parameters[f"{ax}max"] for ax in "xyz"]).astype("float64") if self.dimensionality < 3: - for d in [dimensionality] + list(range(3 - dimensionality)): + for d in range(self.dimensionality, 3): if dle[d] == dre[d]: mylog.warning( "Identical domain left edge and right edges " diff --git a/yt/frontends/sdf/data_structures.py b/yt/frontends/sdf/data_structures.py index ebe217eb0b5..f5c05f3bcbf 100644 --- a/yt/frontends/sdf/data_structures.py +++ b/yt/frontends/sdf/data_structures.py @@ -187,8 +187,11 @@ def _is_valid(cls, filename, *args, **kwargs): # Grab a whole 4k page. line = next(hreq.iter_content(4096)) elif os.path.isfile(sdf_header): - with open(sdf_header, encoding="ISO-8859-1") as f: - line = f.read(10).strip() + try: + with open(sdf_header, encoding="ISO-8859-1") as f: + line = f.read(10).strip() + except PermissionError: + return False else: return False return line.startswith("# SDF") diff --git a/yt/loaders.py b/yt/loaders.py index 64fb83192ad..bfc525cf0af 100644 --- a/yt/loaders.py +++ b/yt/loaders.py @@ -83,7 +83,7 @@ def load( yt.utilities.exceptions.YTAmbiguousDataType If the data format matches more than one class of similar specilization levels. """ - fn = os.fspath(fn) + fn = os.path.expanduser(fn) if any(wildcard in fn for wildcard in "[]?!*"): from yt.data_objects.time_series import DatasetSeries diff --git a/yt/visualization/base_plot_types.py b/yt/visualization/base_plot_types.py index b5774ba5603..682881b0639 100644 --- a/yt/visualization/base_plot_types.py +++ b/yt/visualization/base_plot_types.py @@ -2,13 +2,11 @@ import warnings from abc import ABC from io import BytesIO -from typing import Optional, Tuple, Union +from typing import TYPE_CHECKING, Optional, Tuple, Union import matplotlib import numpy as np -from matplotlib.axis import Axis from matplotlib.colors import LogNorm, Normalize, SymLogNorm -from matplotlib.figure import Figure from matplotlib.ticker import LogFormatterMathtext from packaging.version import Version @@ -23,6 +21,10 @@ validate_image_name, ) +if TYPE_CHECKING: + from matplotlib.axis import Axis + from matplotlib.figure import Figure + BACKEND_SPECS = { "GTK": ["backend_gtk", "FigureCanvasGTK", "FigureManagerGTK"], "GTKAgg": ["backend_gtkagg", "FigureCanvasGTKAgg", None], @@ -91,8 +93,8 @@ def __init__( axrect, *, norm_handler: NormHandler, - figure: Optional[Figure] = None, - axes: Optional[Axis] = None, + figure: Optional["Figure"] = None, + axes: Optional["Axis"] = None, ): """Initialize PlotMPL class""" import matplotlib.figure @@ -198,7 +200,7 @@ def _set_font_properties(self, font_properties, font_color): for label in self._get_labels(): label.set_fontproperties(font_properties) if font_color is not None: - label.set_color(self.font_color) + label.set_color(font_color) def _repr_png_(self): from ._mpl_imports import FigureCanvasAgg @@ -224,9 +226,9 @@ def __init__( *, norm_handler: NormHandler, colorbar_handler: ColorbarHandler, - figure: Optional[Figure] = None, - axes: Optional[Axis] = None, - cax: Optional[Axis] = None, + figure: Optional["Figure"] = None, + axes: Optional["Axis"] = None, + cax: Optional["Axis"] = None, ): """Initialize ImagePlotMPL class object""" self.colorbar_handler = colorbar_handler diff --git a/yt/visualization/tests/test_plotwindow.py b/yt/visualization/tests/test_plotwindow.py index 0845af8a8d9..af9aae04e4a 100644 --- a/yt/visualization/tests/test_plotwindow.py +++ b/yt/visualization/tests/test_plotwindow.py @@ -913,3 +913,19 @@ def test_invalid_swap_projection(): slc.set_mpl_projection("Robinson") slc.swap_axes() # should raise mylog.warning and not toggle _swap_axes assert slc._has_swapped_axes is False + + +def test_set_font(): + # simply check that calling the set_font method doesn't raise an error + # https://github.com/yt-project/yt/issues/4263 + ds = fake_amr_ds() + slc = SlicePlot(ds, "x", "Density") + slc.set_font( + { + "family": "sans-serif", + "style": "italic", + "weight": "bold", + "size": 24, + "color": "blue", + } + )