Skip to content

Commit

Permalink
Merge branch 'main' into pandas-stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
headtr1ck committed Jul 13, 2024
2 parents 07a52ae + d8b7644 commit a93bba6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
Empty file added properties/__init__.py
Empty file.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ exclude_lines = ["pragma: no cover", "if TYPE_CHECKING"]
[tool.mypy]
enable_error_code = "redundant-self"
exclude = [
'build',
'xarray/util/generate_.*\.py',
'xarray/datatree_/doc/.*\.py',
]
Expand Down
37 changes: 21 additions & 16 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ def setup(self) -> Generator:
plt.close("all")

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()
fig, axs = plt.subplots(ncols=2, subplot_kw=subplot_kw, squeeze=False)
ax = axs[0, 0]
plotmethod(ax=ax)
assert ax.has_data()

@pytest.mark.slow
def imshow_called(self, plotmethod) -> bool:
Expand Down Expand Up @@ -240,9 +241,9 @@ def test_1d_x_y_kw(self) -> None:

xy: list[list[None | str]] = [[None, None], [None, "z"], ["z", None]]

f, ax = plt.subplots(3, 1)
f, axs = plt.subplots(3, 1, squeeze=False)
for aa, (x, y) in enumerate(xy):
da.plot(x=x, y=y, ax=ax.flat[aa])
da.plot(x=x, y=y, ax=axs.flat[aa])

with pytest.raises(ValueError, match=r"Cannot specify both"):
da.plot(x="z", y="z")
Expand Down Expand Up @@ -1568,7 +1569,9 @@ def test_colorbar_kwargs(self) -> None:
assert "MyLabel" in alltxt
assert "testvar" not in alltxt
# change cbar ax
fig, (ax, cax) = plt.subplots(1, 2)
fig, axs = plt.subplots(1, 2, squeeze=False)
ax = axs[0, 0]
cax = axs[0, 1]
self.plotmethod(
ax=ax, cbar_ax=cax, add_colorbar=True, cbar_kwargs={"label": "MyBar"}
)
Expand All @@ -1578,7 +1581,9 @@ def test_colorbar_kwargs(self) -> None:
assert "MyBar" in alltxt
assert "testvar" not in alltxt
# note that there are two ways to achieve this
fig, (ax, cax) = plt.subplots(1, 2)
fig, axs = plt.subplots(1, 2, squeeze=False)
ax = axs[0, 0]
cax = axs[0, 1]
self.plotmethod(
ax=ax, add_colorbar=True, cbar_kwargs={"label": "MyBar", "cax": cax}
)
Expand Down Expand Up @@ -3373,16 +3378,16 @@ def test_plot1d_default_rcparams() -> None:
# see overlapping markers:
fig, ax = plt.subplots(1, 1)
ds.plot.scatter(x="A", y="B", marker="o", ax=ax)
np.testing.assert_allclose(
ax.collections[0].get_edgecolor(), mpl.colors.to_rgba_array("w")
)
actual: np.ndarray = mpl.colors.to_rgba_array("w")
expected: np.ndarray = ax.collections[0].get_edgecolor() # type: ignore[assignment] # mpl error?
np.testing.assert_allclose(actual, expected)

# Facetgrids should have the default value as well:
fg = ds.plot.scatter(x="A", y="B", col="x", marker="o")
ax = fg.axs.ravel()[0]
np.testing.assert_allclose(
ax.collections[0].get_edgecolor(), mpl.colors.to_rgba_array("w")
)
actual = mpl.colors.to_rgba_array("w")
expected = ax.collections[0].get_edgecolor() # type: ignore[assignment] # mpl error?
np.testing.assert_allclose(actual, expected)

# scatter should not emit any warnings when using unfilled markers:
with assert_no_warnings():
Expand All @@ -3392,9 +3397,9 @@ def test_plot1d_default_rcparams() -> None:
# Prioritize edgecolor argument over default plot1d values:
fig, ax = plt.subplots(1, 1)
ds.plot.scatter(x="A", y="B", marker="o", ax=ax, edgecolor="k")
np.testing.assert_allclose(
ax.collections[0].get_edgecolor(), mpl.colors.to_rgba_array("k")
)
actual = mpl.colors.to_rgba_array("k")
expected = ax.collections[0].get_edgecolor() # type: ignore[assignment] # mpl error?
np.testing.assert_allclose(actual, expected)


@requires_matplotlib
Expand Down

0 comments on commit a93bba6

Please sign in to comment.