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

Bug: assert_produces_warning(None) not raising AssertionError with warning #38626

Merged
merged 8 commits into from
Dec 22, 2020

Conversation

mzeitlin11
Copy link
Member

@mzeitlin11 mzeitlin11 marked this pull request as draft December 21, 2020 20:14
@mzeitlin11
Copy link
Member Author

These changes cause 23 test failures from tm.assert_produces_warning(None) now actually raising an AssertionError if a warning is given. What is the right approach here? Should those tests just be xfailed and an issue made to look into those warnings?

@@ -2724,11 +2724,10 @@ class for all warnings. To check that no warning is returned,
extra_warnings = []

for actual_warning in w:
Copy link
Member

Choose a reason for hiding this comment

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

isn't this code functionally the same as existing?

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 thought if expected_warning is False or None, then extra_warnings does not get appended to because of the continue. So the check at the end for raising on extra warnings doesn't get triggered.

Copy link
Member

@ivanovmg ivanovmg Dec 21, 2020

Choose a reason for hiding this comment

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

Current implementation will ignore the else clause below, which consolidates extra warnings. I see that I messed that up in one of my previous PRs. This PR reverts that error.
Probably, if some functions are extracted, that would improve the readability of the logic (maybe in a separate PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

The added tests do raise on master as well, so behavior for them has changed

Copy link
Member

@ivanovmg ivanovmg left a comment

Choose a reason for hiding this comment

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

Looks like this fixes the issue reported.
Let us take a look at the failing tests.

Comment on lines -2727 to +2730
if not expected_warning:
continue

expected_warning = cast(Type[Warning], expected_warning)
if issubclass(actual_warning.category, expected_warning):
if expected_warning and issubclass(
actual_warning.category, expected_warning
):
Copy link
Member

Choose a reason for hiding this comment

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

Yes, this is a good catch.

@@ -152,3 +152,20 @@ def test_right_category_wrong_match_raises(pair_different_warnings):
with tm.assert_produces_warning(target_category, match=r"^Match this"):
warnings.warn("Do not match it", target_category)
warnings.warn("Match this", other_category)


@pytest.mark.parametrize("false_or_none", [False, None])
Copy link
Member

Choose a reason for hiding this comment

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

Good tests to prevent the issue from happening!

@arw2019 arw2019 added the Testing pandas testing functions or related to the test suite label Dec 21, 2020
@jreback
Copy link
Contributor

jreback commented Dec 21, 2020

wow

FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'UTC']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'US/Eastern']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'Asia/Tokyo']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'dateutil/US/Pacific']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'dateutil/Asia/Singapore']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'+01:15']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'-02:15']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'UTC+01:15']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-'UTC-02:15']
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-tzutc()]
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-tzlocal()]
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-pytz.FixedOffset(300)]
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-<UTC>]
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-pytz.FixedOffset(-300)]
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-datetime.timezone.utc]
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-datetime.timezone(datetime.timedelta(seconds=3600))]
FAILED pandas/tests/arithmetic/test_timedelta64.py::TestTimedelta64ArithmeticUnsorted::test_tda_add_dt64_object_array[DataFrame-datetime.timezone(datetime.timedelta(days=-1, seconds=82800), 'foo')]
FAILED pandas/tests/frame/test_arithmetic.py::TestFrameArithmetic::test_binop_other[add-True-bool]
FAILED pandas/tests/frame/test_arithmetic.py::TestFrameArithmetic::test_binop_other[mul-True-bool]
FAILED pandas/tests/indexes/test_common.py::TestCommon::test_asi8_deprecation[int]
FAILED pandas/tests/indexes/test_common.py::TestCommon::test_asi8_deprecation[uint]
FAILED pandas/tests/indexes/test_common.py::TestCommon::test_asi8_deprecation[range]
FAILED pandas/tests/indexes/test_common.py::TestCommon::test_asi8_deprecation[repeats]

ok these at least should be straightforward to fix

@mzeitlin11
Copy link
Member Author

Bottom 4 failures can be fixed by removing Int64Index and UInt64Index from the tuple in

if isinstance(
index, (Int64Index, UInt64Index, DatetimeIndex, TimedeltaIndex, PeriodIndex)

Looks like this deprecation came from #37877, this removal would make sense if those indexes should give a FutureWarning with .asi8 (as currently happens in master). cc @jbrockmendel

@jreback
Copy link
Contributor

jreback commented Dec 22, 2020

Bottom 4 failures can be fixed by removing Int64Index and UInt64Index from the tuple in

if isinstance(
index, (Int64Index, UInt64Index, DatetimeIndex, TimedeltaIndex, PeriodIndex)

Looks like this deprecation came from #37877, this removal would make sense if those indexes should give a FutureWarning with .asi8 (as currently happens in master). cc @jbrockmendel

can also just xfail these 3 tests and open an issue as well.

@@ -543,6 +543,7 @@ def test_tda_add_sub_index(self):
expected = tdi - tdi
tm.assert_index_equal(result, expected)

@pytest.mark.xfail(reason="GH38630", strict=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason you are passing strict? we default to true - eg if these are fixed we want the tests to fail (as a hint to remove the xfail)

Copy link
Member Author

Choose a reason for hiding this comment

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

Problem I ran into is that some parameterizations actually pass, so strict=True fails for these. Couldn't figure out a way to xfail only the failing combinations because the parameterizations are complex (2 defined elsewhere in fixtures, 1 uses multiple calls to pytest.mark.parametrize).

Copy link
Contributor

Choose a reason for hiding this comment

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

ok that's fine

ping on green

Copy link
Member Author

Choose a reason for hiding this comment

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

Seeing 2 failures where pandas/tests/io/parser/test_common.py::test_chunks_have_consistent_numerical_type[python] gives unexpected ResourceWarning.

Do you know if this warning occurs consistently? Should something in the test be modified to handle a potential ResourceWarning? Or just another xfail case?

Copy link
Contributor

Choose a reason for hiding this comment

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

we ar trying to track these cases down as something is leaking

if they r causing actual failures then ok to xfail (and list these in the associated issue with checkboxes)

@mzeitlin11 mzeitlin11 marked this pull request as ready for review December 22, 2020 03:36
@mzeitlin11
Copy link
Member Author

Green except Travis

@jreback jreback added this to the 1.3 milestone Dec 22, 2020
@jreback jreback merged commit 0519914 into pandas-dev:master Dec 22, 2020
@jreback
Copy link
Contributor

jreback commented Dec 22, 2020

thanks @mzeitlin11 keep em coming!

@mzeitlin11 mzeitlin11 deleted the bug/assert_produces_warning branch December 22, 2020 14:31
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
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: tm.assert_produces_warning() doesn't work with expected_warning=None or False
4 participants