forked from pandas-dev/pandas
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REGR: Better warning in pivot_table when dropping nuisance columns (p…
…andas-dev#49615) * REGR: Better warning in pivot_table when dropping nuisance columns * type-hint fixups (cherry picked from commit ab89c53)
- Loading branch information
1 parent
1b8e4db
commit 8d80e0b
Showing
4 changed files
with
101 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import warnings | ||
|
||
import pytest | ||
|
||
from pandas.util._exceptions import rewrite_warning | ||
|
||
import pandas._testing as tm | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"target_category, target_message, hit", | ||
[ | ||
(FutureWarning, "Target message", True), | ||
(FutureWarning, "Target", True), | ||
(FutureWarning, "get mess", True), | ||
(FutureWarning, "Missed message", False), | ||
(DeprecationWarning, "Target message", False), | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"new_category", | ||
[ | ||
None, | ||
DeprecationWarning, | ||
], | ||
) | ||
def test_rewrite_warning(target_category, target_message, hit, new_category): | ||
new_message = "Rewritten message" | ||
if hit: | ||
expected_category = new_category if new_category else target_category | ||
expected_message = new_message | ||
else: | ||
expected_category = FutureWarning | ||
expected_message = "Target message" | ||
with tm.assert_produces_warning(expected_category, match=expected_message): | ||
with rewrite_warning( | ||
target_message, target_category, new_message, new_category | ||
): | ||
warnings.warn(message="Target message", category=FutureWarning) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters