From 7534116122b42346d843f01f7f111f2a70122aec Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:43:06 +0100 Subject: [PATCH 01/17] Update pyproject.toml --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d2a5c6b8748..45047f78623 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -176,7 +176,6 @@ module = [ "xarray.tests.test_merge", "xarray.tests.test_missing", "xarray.tests.test_parallelcompat", - "xarray.tests.test_plot", "xarray.tests.test_sparse", "xarray.tests.test_ufuncs", "xarray.tests.test_units", From a980fa2d14eb812532799e25ae101139b4a7ef94 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:49:51 +0100 Subject: [PATCH 02/17] Update test_plot.py --- xarray/tests/test_plot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 6f983a121fe..072e070fe1d 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -85,19 +85,19 @@ def test_all_figures_closed(): @pytest.mark.flaky @pytest.mark.skip(reason="maybe flaky") -def text_in_fig(): +def text_in_fig() -> set(str): """ Return the set of all text in the figure """ return {t.get_text() for t in plt.gcf().findobj(mpl.text.Text)} -def find_possible_colorbars(): +def find_possible_colorbars() -> list[mpl.collections.QuadMesh]: # nb. this function also matches meshes from pcolormesh return plt.gcf().findobj(mpl.collections.QuadMesh) -def substring_in_axes(substring, ax): +def substring_in_axes(substring, ax) -> bool: """ Return True if a substring is found anywhere in an axes """ @@ -108,7 +108,7 @@ def substring_in_axes(substring, ax): return False -def substring_not_in_axes(substring, ax): +def substring_not_in_axes(substring, ax) -> bool: """ Return True if a substring is not found anywhere in an axes """ @@ -117,7 +117,7 @@ def substring_not_in_axes(substring, ax): return all(check) -def property_in_axes_text(property, property_str, target_txt, ax): +def property_in_axes_text(property, property_str, target_txt, ax) -> bool: """ Return True if the specified text in an axes has the property assigned to property_str @@ -130,7 +130,7 @@ def property_in_axes_text(property, property_str, target_txt, ax): return all(check) -def easy_array(shape, start=0, stop=1): +def easy_array(shape: tuple[int, ...], start: float = 0, stop: float = 1) -> np.ndarray: """ Make an array with desired shape using np.linspace @@ -140,7 +140,7 @@ def easy_array(shape, start=0, stop=1): return a.reshape(shape) -def get_colorbar_label(colorbar): +def get_colorbar_label(colorbar) -> str: if colorbar.orientation == "vertical": return colorbar.ax.get_ylabel() else: From 5222c7e8f2f570ef1f519cd377ba7e8d9d4dfe9a Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:55:43 +0100 Subject: [PATCH 03/17] Update test_plot.py --- xarray/tests/test_plot.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 072e070fe1d..22bbb56035c 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -150,27 +150,27 @@ def get_colorbar_label(colorbar) -> str: @requires_matplotlib class PlotTestCase: @pytest.fixture(autouse=True) - def setup(self): + def setup(self) -> None: yield # Remove all matplotlib figures plt.close("all") - def pass_in_axis(self, plotmethod, subplot_kw=None): + def pass_in_axis(self, plotmethod, subplot_kw=None) -> None: fig, axs = plt.subplots(ncols=2, subplot_kw=subplot_kw) plotmethod(ax=axs[0]) assert axs[0].has_data() @pytest.mark.slow - def imshow_called(self, plotmethod): + def imshow_called(self, plotmethod) -> bool: plotmethod() images = plt.gca().findobj(mpl.image.AxesImage) return len(images) > 0 - def contourf_called(self, plotmethod): + def contourf_called(self, plotmethod) -> bool: plotmethod() # Compatible with mpl before (PathCollection) and after (QuadContourSet) 3.8 - def matchfunc(x): + def matchfunc(x) -> bool: return isinstance( x, (mpl.collections.PathCollection, mpl.contour.QuadContourSet) ) @@ -2621,7 +2621,7 @@ def test_facetgrid(self) -> None: (True, "continuous", False, True), ], ) - def test_add_guide(self, add_guide, hue_style, legend, colorbar): + def test_add_guide(self, add_guide, hue_style, legend, colorbar) -> None: meta_data = _infer_meta_data( self.ds, x="x", @@ -2797,7 +2797,7 @@ def test_bad_args( add_legend: bool | None, add_colorbar: bool | None, error_type: type[Exception], - ): + ) -> None: with pytest.raises(error_type): self.ds.plot.scatter( x=x, y=y, hue=hue, add_legend=add_legend, add_colorbar=add_colorbar @@ -2997,7 +2997,7 @@ def test_ncaxis_notinstalled_line_plot(self) -> None: @requires_matplotlib class TestAxesKwargs: @pytest.fixture(params=[1, 2, 3]) - def data_array(self, request): + def data_array(self, request) -> DataArray: """ Return a simple DataArray """ @@ -3010,7 +3010,7 @@ def data_array(self, request): return DataArray(easy_array((10, 3, 2))) @pytest.fixture(params=[1, 2]) - def data_array_logspaced(self, request): + def data_array_logspaced(self, request) -> DataArray: """ Return a simple DataArray with logspaced coordinates """ @@ -3132,7 +3132,7 @@ def test_facetgrid_single_contour() -> None: @requires_matplotlib -def test_get_axis_raises(): +def test_get_axis_raises() -> None: # test get_axis raises an error if trying to do invalid things # cannot provide both ax and figsize From 5886f46b47fdb88f60b9585e4c9449d27f61fd31 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:07:30 +0100 Subject: [PATCH 04/17] Update test_plot.py --- xarray/tests/test_plot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 22bbb56035c..16d1968ca83 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -85,23 +85,23 @@ def test_all_figures_closed(): @pytest.mark.flaky @pytest.mark.skip(reason="maybe flaky") -def text_in_fig() -> set(str): +def text_in_fig() -> set[str]: """ Return the set of all text in the figure """ - return {t.get_text() for t in plt.gcf().findobj(mpl.text.Text)} + return {t.get_text() for t in plt.gcf().findobj(mpl.text.Text)} # type: ignore[attr-defined] # mpl error? def find_possible_colorbars() -> list[mpl.collections.QuadMesh]: # nb. this function also matches meshes from pcolormesh - return plt.gcf().findobj(mpl.collections.QuadMesh) + return plt.gcf().findobj(mpl.collections.QuadMesh) # type: ignore[return-value] # mpl error? -def substring_in_axes(substring, ax) -> bool: +def substring_in_axes(substring: str, ax) -> bool: """ Return True if a substring is found anywhere in an axes """ - alltxt = {t.get_text() for t in ax.findobj(mpl.text.Text)} + alltxt: set[str] = {t.get_text() for t in ax.findobj(mpl.text.Text)} for txt in alltxt: if substring in txt: return True From d7e79bb5f3d7fa4545d018f5d9a2aa3f6585612b Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:16:06 +0100 Subject: [PATCH 05/17] Update test_plot.py --- xarray/tests/test_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 16d1968ca83..1cc25d5615a 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -6,7 +6,7 @@ from collections.abc import Hashable from copy import copy from datetime import datetime -from typing import Any, Callable, Literal +from typing import Any, Callable, Literal, Generator import numpy as np import pandas as pd @@ -150,7 +150,7 @@ def get_colorbar_label(colorbar) -> str: @requires_matplotlib class PlotTestCase: @pytest.fixture(autouse=True) - def setup(self) -> None: + def setup(self) -> Generator: yield # Remove all matplotlib figures plt.close("all") From 512f34749c09f1bbdd2495c516d950f8b0732653 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:16:39 +0000 Subject: [PATCH 06/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- xarray/tests/test_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 1cc25d5615a..307fdaf557f 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -3,10 +3,10 @@ import contextlib import inspect import math -from collections.abc import Hashable +from collections.abc import Generator, Hashable from copy import copy from datetime import datetime -from typing import Any, Callable, Literal, Generator +from typing import Any, Callable, Literal import numpy as np import pandas as pd From e467d8daeea4e21ece7247b055be3555cc6c2f87 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:22:21 +0100 Subject: [PATCH 07/17] Update test_plot.py --- xarray/tests/test_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 307fdaf557f..02183e81651 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1236,7 +1236,7 @@ def test_discrete_colormap_list_levels_and_vmin_or_vmax(self) -> None: def test_discrete_colormap_provided_boundary_norm(self) -> None: norm = mpl.colors.BoundaryNorm([0, 5, 10, 15], 4) primitive = self.darray.plot.contourf(norm=norm) - np.testing.assert_allclose(primitive.levels, norm.boundaries) + np.testing.assert_allclose(list(primitive.levels), norm.boundaries) def test_discrete_colormap_provided_boundary_norm_matching_cmap_levels( self, From 3879266592604f5d0268b697313b29dca0b6a7e9 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:27:29 +0100 Subject: [PATCH 08/17] Update test_plot.py --- xarray/tests/test_plot.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 02183e81651..e2c82cad144 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1243,7 +1243,9 @@ def test_discrete_colormap_provided_boundary_norm_matching_cmap_levels( ) -> None: norm = mpl.colors.BoundaryNorm([0, 5, 10, 15], 4) primitive = self.darray.plot.contourf(norm=norm) - assert primitive.colorbar.norm.Ncmap == primitive.colorbar.norm.N + cbar = primitive.colorbar + assert cbar is not None + assert cbar.norm.Ncmap == cbar.norm.N class Common2dMixin: From 7849b9b874acab3b768cb644ee4ae35eb00b4d69 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:46:41 +0100 Subject: [PATCH 09/17] Update test_plot.py --- xarray/tests/test_plot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index e2c82cad144..d0aa96793df 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -3139,11 +3139,11 @@ def test_get_axis_raises() -> None: # cannot provide both ax and figsize with pytest.raises(ValueError, match="both `figsize` and `ax`"): - get_axis(figsize=[4, 4], size=None, aspect=None, ax="something") + get_axis(figsize=[4, 4], size=None, aspect=None, ax="something") # type: ignore[arg-type] # cannot provide both ax and size with pytest.raises(ValueError, match="both `size` and `ax`"): - get_axis(figsize=None, size=200, aspect=4 / 3, ax="something") + get_axis(figsize=None, size=200, aspect=4 / 3, ax="something") # type: ignore[arg-type] # cannot provide both size and figsize with pytest.raises(ValueError, match="both `figsize` and `size`"): @@ -3155,7 +3155,7 @@ def test_get_axis_raises() -> None: # cannot provide axis and subplot_kws with pytest.raises(ValueError, match="cannot use subplot_kws with existing ax"): - get_axis(figsize=None, size=None, aspect=None, ax=1, something_else=5) + get_axis(figsize=None, size=None, aspect=None, ax=1, something_else=5) # type: ignore[arg-type] @requires_matplotlib From 54e6320382dc87efdd49098895b983cc861d512e Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:49:29 +0100 Subject: [PATCH 10/17] Update test_plot.py --- xarray/tests/test_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index d0aa96793df..62e566d011c 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -2999,7 +2999,7 @@ def test_ncaxis_notinstalled_line_plot(self) -> None: @requires_matplotlib class TestAxesKwargs: @pytest.fixture(params=[1, 2, 3]) - def data_array(self, request) -> DataArray: + def data_array(self, request) -> Generator[None, None, DataArray]: """ Return a simple DataArray """ @@ -3012,7 +3012,7 @@ def data_array(self, request) -> DataArray: return DataArray(easy_array((10, 3, 2))) @pytest.fixture(params=[1, 2]) - def data_array_logspaced(self, request) -> DataArray: + def data_array_logspaced(self, request) -> Generator[None, None, DataArray]: """ Return a simple DataArray with logspaced coordinates """ From ef678d2714cf35322ecbd3acac27b46ab4e57d42 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 12:55:21 +0100 Subject: [PATCH 11/17] Update test_plot.py --- xarray/tests/test_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 62e566d011c..d0aa96793df 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -2999,7 +2999,7 @@ def test_ncaxis_notinstalled_line_plot(self) -> None: @requires_matplotlib class TestAxesKwargs: @pytest.fixture(params=[1, 2, 3]) - def data_array(self, request) -> Generator[None, None, DataArray]: + def data_array(self, request) -> DataArray: """ Return a simple DataArray """ @@ -3012,7 +3012,7 @@ def data_array(self, request) -> Generator[None, None, DataArray]: return DataArray(easy_array((10, 3, 2))) @pytest.fixture(params=[1, 2]) - def data_array_logspaced(self, request) -> Generator[None, None, DataArray]: + def data_array_logspaced(self, request) -> DataArray: """ Return a simple DataArray with logspaced coordinates """ From bb94c745cea4d3e8c410c890eb4f32ff2f354b34 Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:01:58 +0100 Subject: [PATCH 12/17] Update test_plot.py --- xarray/tests/test_plot.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index d0aa96793df..b8aac0707ea 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -97,7 +97,7 @@ def find_possible_colorbars() -> list[mpl.collections.QuadMesh]: return plt.gcf().findobj(mpl.collections.QuadMesh) # type: ignore[return-value] # mpl error? -def substring_in_axes(substring: str, ax) -> bool: +def substring_in_axes(substring: Hashable, ax: mpl.axes) -> bool: """ Return True if a substring is found anywhere in an axes """ @@ -108,7 +108,7 @@ def substring_in_axes(substring: str, ax) -> bool: return False -def substring_not_in_axes(substring, ax) -> bool: +def substring_not_in_axes(substring: Hashable, ax: mpl.axes) -> bool: """ Return True if a substring is not found anywhere in an axes """ @@ -117,12 +117,12 @@ def substring_not_in_axes(substring, ax) -> bool: return all(check) -def property_in_axes_text(property, property_str, target_txt, ax) -> bool: +def property_in_axes_text(property, property_str, target_txt, ax: mpl.axes) -> bool: """ Return True if the specified text in an axes has the property assigned to property_str """ - alltxt = ax.findobj(mpl.text.Text) + alltxt: list[mpl.text.Text] = ax.findobj(mpl.text.Text) check = [] for t in alltxt: if t.get_text() == target_txt: @@ -2999,7 +2999,7 @@ def test_ncaxis_notinstalled_line_plot(self) -> None: @requires_matplotlib class TestAxesKwargs: @pytest.fixture(params=[1, 2, 3]) - def data_array(self, request) -> DataArray: + def data_array(self, request) -> DataArray: # type: ignore[return] # error: Missing return statement [return] """ Return a simple DataArray """ @@ -3012,7 +3012,7 @@ def data_array(self, request) -> DataArray: return DataArray(easy_array((10, 3, 2))) @pytest.fixture(params=[1, 2]) - def data_array_logspaced(self, request) -> DataArray: + def data_array_logspaced(self, request) -> DataArray: # type: ignore[return] # error: Missing return statement [return] """ Return a simple DataArray with logspaced coordinates """ From 953e692575b3b392f9ed75b64996ccd9e386d85d Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:05:50 +0100 Subject: [PATCH 13/17] Update test_plot.py --- xarray/tests/test_plot.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index b8aac0707ea..698efd7769b 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -97,7 +97,7 @@ def find_possible_colorbars() -> list[mpl.collections.QuadMesh]: return plt.gcf().findobj(mpl.collections.QuadMesh) # type: ignore[return-value] # mpl error? -def substring_in_axes(substring: Hashable, ax: mpl.axes) -> bool: +def substring_in_axes(substring: Hashable, ax: mpl.axes.Axes) -> bool: """ Return True if a substring is found anywhere in an axes """ @@ -108,7 +108,7 @@ def substring_in_axes(substring: Hashable, ax: mpl.axes) -> bool: return False -def substring_not_in_axes(substring: Hashable, ax: mpl.axes) -> bool: +def substring_not_in_axes(substring: Hashable, ax: mpl.axes.Axes) -> bool: """ Return True if a substring is not found anywhere in an axes """ @@ -117,7 +117,9 @@ def substring_not_in_axes(substring: Hashable, ax: mpl.axes) -> bool: return all(check) -def property_in_axes_text(property, property_str, target_txt, ax: mpl.axes) -> bool: +def property_in_axes_text( + property, property_str, target_txt, ax: mpl.axes.Axes +) -> bool: """ Return True if the specified text in an axes has the property assigned to property_str From 04dc84f740a5dbe64dfbcf416ce13c31cefe300d Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:13:10 +0100 Subject: [PATCH 14/17] Update test_plot.py --- xarray/tests/test_plot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 698efd7769b..449003f6664 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -97,7 +97,7 @@ def find_possible_colorbars() -> list[mpl.collections.QuadMesh]: return plt.gcf().findobj(mpl.collections.QuadMesh) # type: ignore[return-value] # mpl error? -def substring_in_axes(substring: Hashable, ax: mpl.axes.Axes) -> bool: +def substring_in_axes(substring: str, ax: mpl.axes.Axes) -> bool: """ Return True if a substring is found anywhere in an axes """ @@ -108,11 +108,11 @@ def substring_in_axes(substring: Hashable, ax: mpl.axes.Axes) -> bool: return False -def substring_not_in_axes(substring: Hashable, ax: mpl.axes.Axes) -> bool: +def substring_not_in_axes(substring: str, ax: mpl.axes.Axes) -> bool: """ Return True if a substring is not found anywhere in an axes """ - alltxt = {t.get_text() for t in ax.findobj(mpl.text.Text)} + alltxt: set[str] = {t.get_text() for t in ax.findobj(mpl.text.Text)} # type: ignore[attr-defined] # mpl error? check = [(substring not in txt) for txt in alltxt] return all(check) @@ -124,7 +124,7 @@ def property_in_axes_text( Return True if the specified text in an axes has the property assigned to property_str """ - alltxt: list[mpl.text.Text] = ax.findobj(mpl.text.Text) + alltxt: list[mpl.text.Text] = ax.findobj(mpl.text.Text) # type: ignore[assignment] check = [] for t in alltxt: if t.get_text() == target_txt: From 0e8695c02ec0f72ac01be3204e9c55909a53f11a Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:17:56 +0100 Subject: [PATCH 15/17] Update test_plot.py --- xarray/tests/test_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 449003f6664..69e0c0f87cc 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -101,7 +101,7 @@ def substring_in_axes(substring: str, ax: mpl.axes.Axes) -> bool: """ Return True if a substring is found anywhere in an axes """ - alltxt: set[str] = {t.get_text() for t in ax.findobj(mpl.text.Text)} + alltxt: set[str] = {t.get_text() for t in ax.findobj(mpl.text.Text)} # type: ignore[attr-defined] # mpl error? for txt in alltxt: if substring in txt: return True @@ -2522,7 +2522,7 @@ def test_default_labels(self) -> None: # Leftmost column should have array name for ax in g.axs[:, 0]: - assert substring_in_axes(self.darray.name, ax) + assert substring_in_axes(str(self.darray.name), ax) def test_test_empty_cell(self) -> None: g = ( From 729bdadd9f06d34a36d08a84d700bbf96b970dbb Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Fri, 29 Mar 2024 13:26:34 +0100 Subject: [PATCH 16/17] Update test_plot.py --- xarray/tests/test_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 69e0c0f87cc..8b6d8b1907a 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1247,7 +1247,7 @@ def test_discrete_colormap_provided_boundary_norm_matching_cmap_levels( primitive = self.darray.plot.contourf(norm=norm) cbar = primitive.colorbar assert cbar is not None - assert cbar.norm.Ncmap == cbar.norm.N + assert cbar.norm.Ncmap == cbar.norm.N # type: ignore[attr-defined] # Exists, debatable if public though. class Common2dMixin: From c84ec31321637662e268b57678372d98bf296c6b Mon Sep 17 00:00:00 2001 From: Illviljan <14371165+Illviljan@users.noreply.github.com> Date: Sat, 30 Mar 2024 21:07:51 +0100 Subject: [PATCH 17/17] raise ValueError if too many dims are requested --- xarray/tests/test_plot.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index b1678ebacbb..e636be5589f 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -3015,20 +3015,22 @@ def test_ncaxis_notinstalled_line_plot(self) -> None: @requires_matplotlib class TestAxesKwargs: @pytest.fixture(params=[1, 2, 3]) - def data_array(self, request) -> DataArray: # type: ignore[return] # error: Missing return statement [return] + def data_array(self, request) -> DataArray: """ Return a simple DataArray """ dims = request.param if dims == 1: return DataArray(easy_array((10,))) - if dims == 2: + elif dims == 2: return DataArray(easy_array((10, 3))) - if dims == 3: + elif dims == 3: return DataArray(easy_array((10, 3, 2))) + else: + raise ValueError(f"No DataArray implemented for {dims=}.") @pytest.fixture(params=[1, 2]) - def data_array_logspaced(self, request) -> DataArray: # type: ignore[return] # error: Missing return statement [return] + def data_array_logspaced(self, request) -> DataArray: """ Return a simple DataArray with logspaced coordinates """ @@ -3037,12 +3039,14 @@ def data_array_logspaced(self, request) -> DataArray: # type: ignore[return] # return DataArray( np.arange(7), dims=("x",), coords={"x": np.logspace(-3, 3, 7)} ) - if dims == 2: + elif dims == 2: return DataArray( np.arange(16).reshape(4, 4), dims=("y", "x"), coords={"x": np.logspace(-1, 2, 4), "y": np.logspace(-5, -1, 4)}, ) + else: + raise ValueError(f"No DataArray implemented for {dims=}.") @pytest.mark.parametrize("xincrease", [True, False]) def test_xincrease_kwarg(self, data_array, xincrease) -> None: