Skip to content
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

TST: fix warning for pie chart #37669

Merged
merged 4 commits into from
Nov 8, 2020
Merged
Changes from 2 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
11 changes: 10 additions & 1 deletion pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2650,11 +2650,20 @@ def test_pie_df(self):
self._check_colors(ax.patches, facecolors=color_args)

def test_pie_df_nan(self):
import matplotlib as mpl

df = DataFrame(np.random.rand(4, 4))
for i in range(4):
df.iloc[i, i] = np.nan
fig, axes = self.plt.subplots(ncols=4)
df.plot.pie(subplots=True, ax=axes, legend=True)

# GH 37668
if mpl.__version__ >= "3.3":
kwargs = {"normalize": True}
else:
kwargs = {}

df.plot.pie(subplots=True, ax=axes, legend=True, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

since we are explicitly fixing the warning, should we do something like to ensure the warning is gone?

with tm.assert_produces_warning(None):
    df.plot.pie(subplots=True, ax=axes, legend=True, **kwargs)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for the hint!
Since, the warning is relevant only for the newer matplotlib versions, thus I implemented checking that no warning is raised only for this case.
Meanwhile for the older version there is no need to check for warnings.
There is a slight code repetition, which I can easily overcome (make kwargs dict), if required.
How does it look like?

Copy link
Member

Choose a reason for hiding this comment

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

I slightly prefer to use kwargs, and we should check no warning is produced regardless of mpl version, so something like below is enough for me (instead of only doing the warning check on mpl>3.3):

kwargs = {}
if mpl.__version__ >= "3.3":
     kwargs = {"normalize": True}

with tm.assert_produces_warning(None):
    df.plot.pie(subplots=True, ax=axes, legend=True, **kwargs)

how does it look to you?


base_expected = ["0", "1", "2", "3"]
for i, ax in enumerate(axes):
Expand Down