Skip to content

DOC: added type annotations and tests to check for multiple warning match #47833

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 21 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
86024b5
Testing
shourya5 Jul 23, 2022
b845f98
TST: added a test for multiple warnings
shourya5 Jul 23, 2022
8609ea4
TYP: added type annotation Tuple[Type[Warning], ...] in assert_produ…
shourya5 Jul 23, 2022
d5c5150
TST: added a test for multiple warnings
shourya5 Jul 23, 2022
9915069
Merge branch 'issue#47829' of https://github.com/shourya5/pandas into…
shourya5 Jul 23, 2022
8c418c4
Merge branch 'pandas-dev:main' into issue#47829
shourya5 Jul 24, 2022
4346683
Merge branch 'pandas-dev:main' into issue#47829
shourya5 Jul 31, 2022
e7a32f8
TYP: Fixed Annotations
shourya5 Jul 31, 2022
d980f42
TST: Test for catching multiple warnings
shourya5 Jul 31, 2022
474c84f
TST: Test for catching multiple warnings
shourya5 Jul 31, 2022
a615ac6
TST: Test for catching multiple warnings
shourya5 Jul 31, 2022
888befb
TYP : fixed type annotations in _assert_caught_no_extra_warnings
shourya5 Aug 1, 2022
a546c6a
TYP : updated type annotations
shourya5 Aug 1, 2022
6ad3ba9
DOC : added issue as inline comment
shourya5 Aug 1, 2022
67a5ec7
Merge branch 'main' into issue#47829
shourya5 Aug 1, 2022
4406841
DOC : added some documentation regarding type annotations
shourya5 Aug 2, 2022
efbed59
Merge branch 'pandas-dev:main' into issue#47829
shourya5 Aug 2, 2022
95cef2b
DOC : fixed pre-commit errors
shourya5 Aug 2, 2022
9808934
Merge branch 'issue#47829' of https://github.com/shourya5/pandas into…
shourya5 Aug 2, 2022
09262ab
fix missing whitespace
MarcoGorelli Aug 2, 2022
7907820
Merge branch 'main' into issue#47829
shourya5 Aug 3, 2022
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
7 changes: 4 additions & 3 deletions pandas/_testing/_warnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import (
Literal,
Sequence,
Tuple,
Type,
cast,
)
Expand All @@ -17,7 +18,7 @@

@contextmanager
def assert_produces_warning(
expected_warning: type[Warning] | bool | None = Warning,
expected_warning: type[Warning] | bool | Tuple[type[Warning], ...] | None = Warning,
filter_level: Literal[
"error", "ignore", "always", "default", "module", "once"
] = "always",
Expand Down Expand Up @@ -157,7 +158,7 @@ def _assert_caught_expected_warning(
def _assert_caught_no_extra_warnings(
*,
caught_warnings: Sequence[warnings.WarningMessage],
expected_warning: type[Warning] | bool | None,
expected_warning: type[Warning] | bool | Tuple[type[Warning], ...] | None,
) -> None:
"""Assert that no extra warnings apart from the expected ones are caught."""
extra_warnings = []
Expand Down Expand Up @@ -195,7 +196,7 @@ def _assert_caught_no_extra_warnings(

def _is_unexpected_warning(
actual_warning: warnings.WarningMessage,
expected_warning: type[Warning] | bool | None,
expected_warning: type[Warning] | bool | Tuple[type[Warning], ...] | None,
) -> bool:
"""Check if the actual warning issued is unexpected."""
if actual_warning and not expected_warning:
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/util/test_assert_produces_warning.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ def test_same_category_different_messages_last_match():
warnings.warn("Do not match that either", category)
warnings.warn("Match this", category)

def test_match_multiple_warnings():
#https://github.com/pandas-dev/pandas/issues/47829
category = (FutureWarning, UserWarning)
with tm.assert_produces_warning(category, match=r"^Match this"):
warnings.warn("Match this",FutureWarning )
warnings.warn("Match this too", UserWarning)



def test_right_category_wrong_match_raises(pair_different_warnings):
target_category, other_category = pair_different_warnings
Expand Down