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

TST: tighten xfails #38309

Merged
merged 2 commits into from
Dec 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 10 additions & 15 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import numpy as np
import pytest
import pytz

from pandas._libs import NaT, OutOfBoundsDatetime, Timestamp
from pandas.compat.numpy import np_version_under1p18
Expand Down Expand Up @@ -269,18 +268,16 @@ def test_searchsorted(self):
assert result == 10

@pytest.mark.parametrize("box", [None, "index", "series"])
def test_searchsorted_castable_strings(self, arr1d, box):
def test_searchsorted_castable_strings(self, arr1d, box, request):
if isinstance(arr1d, DatetimeArray):
tz = arr1d.tz
if (
tz is not None
and tz is not pytz.UTC
and not isinstance(tz, pytz._FixedOffset)
):
ts1, ts2 = arr1d[1:3]
if tz is not None and ts1.tz.tzname(ts1) != ts2.tz.tzname(ts2):
# If we have e.g. tzutc(), when we cast to string and parse
# back we get pytz.UTC, and then consider them different timezones
# so incorrectly raise.
pytest.xfail(reason="timezone comparisons inconsistent")
mark = pytest.mark.xfail(reason="timezone comparisons inconsistent")
request.node.add_marker(mark)

arr = arr1d
if box is None:
Expand Down Expand Up @@ -391,19 +388,17 @@ def test_setitem(self):
expected[:2] = expected[-2:]
tm.assert_numpy_array_equal(arr.asi8, expected)

def test_setitem_strs(self, arr1d):
def test_setitem_strs(self, arr1d, request):
# Check that we parse strs in both scalar and listlike
if isinstance(arr1d, DatetimeArray):
tz = arr1d.tz
if (
tz is not None
and tz is not pytz.UTC
and not isinstance(tz, pytz._FixedOffset)
):
ts1, ts2 = arr1d[-2:]
if tz is not None and ts1.tz.tzname(ts1) != ts2.tz.tzname(ts2):
# If we have e.g. tzutc(), when we cast to string and parse
# back we get pytz.UTC, and then consider them different timezones
# so incorrectly raise.
pytest.xfail(reason="timezone comparisons inconsistent")
mark = pytest.mark.xfail(reason="timezone comparisons inconsistent")
request.node.add_marker(mark)

# Setting list-like of strs
expected = arr1d.copy()
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/base/test_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,16 @@ def test_array_multiindex_raises():
),
],
)
def test_to_numpy(array, expected, index_or_series_or_array):
def test_to_numpy(array, expected, index_or_series_or_array, request):
box = index_or_series_or_array
thing = box(array)

if array.dtype.name in ("Int64", "Sparse[int64, 0]") and box is pd.Index:
pytest.skip(f"No index type for {array.dtype}")

if array.dtype.name == "int64" and box is pd.array:
pytest.xfail("thing is Int64 and to_numpy() returns object")
mark = pytest.mark.xfail(reason="thing is Int64 and to_numpy() returns object")
request.node.add_marker(mark)

result = thing.to_numpy()
tm.assert_numpy_array_equal(result, expected)
Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/indexes/test_numpy_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,16 @@ def test_numpy_ufuncs_basic(index, func):
@pytest.mark.parametrize(
"func", [np.isfinite, np.isinf, np.isnan, np.signbit], ids=lambda x: x.__name__
)
def test_numpy_ufuncs_other(index, func):
def test_numpy_ufuncs_other(index, func, request):
# test ufuncs of numpy, see:
# https://numpy.org/doc/stable/reference/ufuncs.html

if isinstance(index, (DatetimeIndex, TimedeltaIndex)):
if isinstance(index, DatetimeIndex) and index.tz is not None:
if func in [np.isfinite, np.isnan, np.isinf]:
pytest.xfail(reason="__array_ufunc__ is not defined")
if not np_version_under1p17:
Copy link
Contributor

@jreback jreback Dec 5, 2020

Choose a reason for hiding this comment

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

why do we not prefer an inside use of pytest.xfail and this format instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

using pytest.xfail breaks out immediately, so you dont get alerted if the xfail has been fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

interesting; it doesn't react to strict=True?

Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK thats only when used as a decorator @pytest.mark.xfail(strict=foo)

Copy link
Contributor

Choose a reason for hiding this comment

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

kk

can u update the way to write tests in the docs (open an issue or PR)

also prob need to have a rule which prohibits (open an issue)

mark = pytest.mark.xfail(reason="__array_ufunc__ is not defined")
request.node.add_marker(mark)

if not np_version_under1p18 and func in [np.isfinite, np.isinf, np.isnan]:
# numpy 1.18(dev) changed isinf and isnan to not raise on dt64/tfd64
Expand Down
9 changes: 6 additions & 3 deletions pandas/tests/series/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,15 @@ def test_align_date_objects_with_datetimeindex(self):
)
@pytest.mark.parametrize("box", [list, tuple, np.array, pd.Index, pd.Series, pd.array])
@pytest.mark.parametrize("flex", [True, False])
def test_series_ops_name_retention(flex, box, names, all_binary_operators):
def test_series_ops_name_retention(flex, box, names, all_binary_operators, request):
# GH#33930 consistent name retention
op = all_binary_operators

if op is ops.rfloordiv and box in [list, tuple]:
pytest.xfail("op fails because of inconsistent ndarray-wrapping GH#28759")
if op is ops.rfloordiv and box in [list, tuple] and not flex:
mark = pytest.mark.xfail(
reason="op fails because of inconsistent ndarray-wrapping GH#28759"
)
request.node.add_marker(mark)

left = Series(range(10), name=names[0])
right = Series(range(10), name=names[1])
Expand Down