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

ENH: implement matching warning message #37263

Merged
merged 6 commits into from
Oct 20, 2020

Conversation

ivanovmg
Copy link
Member

Implement matching warning message.
New kwarg match in assert_produces_warning.

@@ -2550,6 +2551,7 @@ def assert_produces_warning(
filter_level="always",
check_stacklevel=True,
raise_on_extra_warnings=True,
match=None,
Copy link
Member

Choose a reason for hiding this comment

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

can you annoate

Copy link
Member Author

Choose a reason for hiding this comment

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

Annotated, but presumably the code became slightly less pythonic. Sorry for that.

],
)
def category(request):
"""Return unique warning.
Copy link
Member

Choose a reason for hiding this comment

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

newline after """

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

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.

comment, but ok to merge after @jbrockmendel doc-string comments.

if raise_on_extra_warnings and extra_warnings:
raise AssertionError(
f"Caused unexpected warning(s): {repr(extra_warnings)}"
)


def _assert_raised_with_correct_stacklevel(actual_warning):
Copy link
Contributor

Choose a reason for hiding this comment

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

bonus points for typing

Copy link
Member Author

Choose a reason for hiding this comment

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

Annotated. IMHO, the type warnings.WarningMessage, although correct, has a confusing name for warning instance.

@jreback jreback added the Testing pandas testing functions or related to the test suite label Oct 20, 2020
@jreback jreback added this to the 1.2 milestone Oct 20, 2020
@ivanovmg ivanovmg requested a review from jreback October 20, 2020 02:50
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

@@ -0,0 +1,138 @@
""""
Test module for testing ``pandas._testing.assert_produces_warning``.
"""
Copy link
Member

Choose a reason for hiding this comment

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

There is already a file with tests for this, in tests/util/test_assert_produces_warning.py, can you move this there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I completely missed it. I moved tests as requested.

@jreback jreback merged commit 77811c7 into pandas-dev:master Oct 20, 2020
@jreback
Copy link
Contributor

jreback commented Oct 20, 2020

thanks @ivanovmg very nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: match warning messages
4 participants