Skip to content

WARN: Catch warning in tests #48753

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pandas/tests/plotting/frame/test_frame_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,18 @@ def test_if_scatterplot_colorbars_are_next_to_parent_axes(self):
@pytest.mark.parametrize("kw", ["c", "color"])
def test_scatter_with_c_column_name_with_colors(self, cmap, kw):
# https://github.com/pandas-dev/pandas/issues/34316
from pandas.plotting._matplotlib.compat import mpl_ge_3_6_0

df = DataFrame(
[[5.1, 3.5], [4.9, 3.0], [7.0, 3.2], [6.4, 3.2], [5.9, 3.0]],
columns=["length", "width"],
)
df["species"] = ["r", "r", "g", "g", "b"]
ax = df.plot.scatter(x=0, y=1, cmap=cmap, **{kw: "species"})
if mpl_ge_3_6_0() and cmap is not None:
with tm.assert_produces_warning(UserWarning, check_stacklevel=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this indicate that we are doing something wrong/outdated?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoGorelli looks like you raised and addressed this issue in #34344

Do you remember if passing cmap in plot.scatter was necessary to test this behavior?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: I think this is a new warning in mpl 3.6 so plot.scatter may have been doing something "wrong" before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was silently ignored before. They added stricter checks in a few places. If we want to check that the colormap is not applied, then we have to check for the user warning

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have some recollection of this issue/PR, I'll take a look tomorrow

ax = df.plot.scatter(x=0, y=1, cmap=cmap, **{kw: "species"})
else:
ax = df.plot.scatter(x=0, y=1, cmap=cmap, **{kw: "species"})
assert ax.collections[0].colorbar is None

def test_scatter_colors(self):
Expand Down