Skip to content

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

Merged

Conversation

moink
Copy link
Member

@moink moink commented Dec 24, 2020

This pull request xref #30999 to remove bare pytest.raises. It doesn't close that issue as I have only addressed files within pandas/tests/plotting/.

Things I did that were not simple adding match = msg to pytest.raises or converting them to tm.external_error_raised:

  • In pandas/plotting/_matplotlib/_core.py I found two error messages somewhat unclear. I changed the error message in the ValueError raised by _get_stacked_values to be, imo, a little bit clearer. In addition, in the constructor for PiePlot, the previous error message for the ValueError 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.
  • In test_frame.py, in the test_errorbar_plot method, the pytest.raises was allowing matplotlib to raise either a TypeError or a ValueError. I changed it to an external_error_raised but also specified it to be a TypeError because that is what it is, and I didn't see the reason it was allowed to be either error.
  • Also in test_frame.py, the test test_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 test test_bad_label
  • Also in test_frame.py, the test test_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.
  • In a couple of test modules I moved a few lines out of the context of the 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.

…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"
Copy link
Member Author

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")
Copy link
Member Author

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):
Copy link
Member Author

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

Copy link
Contributor

@jreback jreback left a comment

Choose a reason for hiding this comment

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

great

@jreback jreback added the Error Reporting Incorrect or improved errors from pandas label Dec 24, 2020
@jreback jreback added this to the 1.3 milestone Dec 24, 2020
@jreback jreback merged commit d481c13 into pandas-dev:master Dec 24, 2020
@jreback
Copy link
Contributor

jreback commented Dec 24, 2020

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).

@moink
Copy link
Member Author

moink commented Dec 24, 2020

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

luckyvs1 pushed a commit to luckyvs1/pandas that referenced this pull request Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants