-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add match=msg to pytest.raises or convert to external_error_raised for modules in tests/plotting #38684
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
Add match=msg to pytest.raises or convert to external_error_raised for modules in tests/plotting #38684
Conversation
…ing/test_boxplot_method.py
…ing/test_frame_color.py
…ing/test_series.py and fixed one error message from "None doesn't allow negative values" to "pie plot doesn't allow negative values"
…ing/test_hist_method.py or convert them to tm.external_error_raised
…ing/frame/test_frame.py or convert them to tm.external_error_raised. Clarify error message in LinePlot._get_stacked_values
"all positive or negative." | ||
f"{label} contains both positive and negative values" | ||
"all positive or all negative. " | ||
f"Column '{label}' contains both positive and negative values" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes the error message a bit clearer.
@@ -1555,7 +1555,7 @@ class PiePlot(MPLPlot): | |||
def __init__(self, data, kind=None, **kwargs): | |||
data = data.fillna(value=0) | |||
if (data < 0).any().any(): | |||
raise ValueError(f"{kind} doesn't allow negative values") | |||
raise ValueError(f"{self._kind} plot doesn't allow negative values") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the test, kind
was None
, and I don't think that was the intent.
df.plot(yerr=np.random.randn(11)) | ||
|
||
df_err = DataFrame({"x": ["zzz"] * 12, "y": ["zzz"] * 12}) | ||
with pytest.raises((ValueError, TypeError)): | ||
with tm.external_error_raised(TypeError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why this previously allowed it to be a ValueError
as well as a TypeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great
thanks @moink FYI on an issue like this use xref rather than closes in the PR header, otherwise GH will acually close the issue (which you normally want, but this issue is not closed yet). |
Ok thanks |
…r modules in tests/plotting (pandas-dev#38684)
This pull request xref #30999 to remove bare
pytest.raises
. It doesn't close that issue as I have only addressed files withinpandas/tests/plotting/
.Things I did that were not simple adding
match = msg
topytest.raises
or converting them totm.external_error_raised
:pandas/plotting/_matplotlib/_core.py
I found two error messages somewhat unclear. I changed the error message in theValueError
raised by_get_stacked_values
to be, imo, a little bit clearer. In addition, in the constructor forPiePlot
, the previous error message for theValueError
was "None doesn't allow negative values" which I changed to "pie plot doesn't allow negative values" because I believe that was the original intent.test_frame.py
, in thetest_errorbar_plot
method, thepytest.raises
was allowing matplotlib to raise either aTypeError
or aValueError
. I changed it to anexternal_error_raised
but also specified it to be aTypeError
because that is what it is, and I didn't see the reason it was allowed to be either error.test_frame.py
, the testtest_invalid_xy_args
was pytest-parameterized to test two different kinds of errors: x not being a label or position, or the label being bad. I split it into two tests, calling the new testtest_bad_label
test_frame.py
, the testtest_partially_invalid_plot_data
looped over a list with one element in it. I guessed that this was a remnant of an older test strategy that is no longer employed. I removed the list and made the kind of plot being tested more explicit.pytest.raises
because they were setup lines that didn't raise the error: I wanted to make it clear exactly which pandas method was raising the error.I will note that another developer, DylanBrdt commented on the issue that they would address these files but they haven't been active on github since February.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff