Skip to content

TST: de-xfail, remove strict=False #33854

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 11 commits into from
Apr 29, 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
37 changes: 19 additions & 18 deletions pandas/tests/arithmetic/test_datetime64.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,9 @@ def test_dti_cmp_nat_behaves_like_float_cmp_nan(self):
"op",
[operator.eq, operator.ne, operator.gt, operator.ge, operator.lt, operator.le],
)
def test_comparison_tzawareness_compat(self, op, box_df_fail):
def test_comparison_tzawareness_compat(self, op, box_with_array):
# GH#18162
box = box_df_fail
box = box_with_array

dr = pd.date_range("2016-01-01", periods=6)
dz = dr.tz_localize("US/Pacific")
Expand All @@ -543,34 +543,35 @@ def test_comparison_tzawareness_compat(self, op, box_df_fail):
with pytest.raises(TypeError, match=msg):
op(dr, dz)

# FIXME: DataFrame case fails to raise for == and !=, wrong
# message for inequalities
if box is pd.DataFrame:
tolist = lambda x: x.astype(object).values.tolist()[0]
else:
tolist = list

with pytest.raises(TypeError, match=msg):
op(dr, list(dz))
op(dr, tolist(dz))
with pytest.raises(TypeError, match=msg):
op(dr, np.array(list(dz), dtype=object))
op(dr, np.array(tolist(dz), dtype=object))
with pytest.raises(TypeError, match=msg):
op(dz, dr)

# FIXME: DataFrame case fails to raise for == and !=, wrong
# message for inequalities
with pytest.raises(TypeError, match=msg):
op(dz, list(dr))
op(dz, tolist(dr))
with pytest.raises(TypeError, match=msg):
op(dz, np.array(list(dr), dtype=object))
op(dz, np.array(tolist(dr), dtype=object))

# The aware==aware and naive==naive comparisons should *not* raise
assert np.all(dr == dr)
assert np.all(dr == list(dr))
assert np.all(list(dr) == dr)
assert np.all(np.array(list(dr), dtype=object) == dr)
assert np.all(dr == np.array(list(dr), dtype=object))
assert np.all(dr == tolist(dr))
assert np.all(tolist(dr) == dr)
assert np.all(np.array(tolist(dr), dtype=object) == dr)
assert np.all(dr == np.array(tolist(dr), dtype=object))

assert np.all(dz == dz)
assert np.all(dz == list(dz))
assert np.all(list(dz) == dz)
assert np.all(np.array(list(dz), dtype=object) == dz)
assert np.all(dz == np.array(list(dz), dtype=object))
assert np.all(dz == tolist(dz))
assert np.all(tolist(dz) == dz)
assert np.all(np.array(tolist(dz), dtype=object) == dz)
assert np.all(dz == np.array(tolist(dz), dtype=object))

@pytest.mark.parametrize(
"op",
Expand Down
38 changes: 23 additions & 15 deletions pandas/tests/arithmetic/test_timedelta64.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,15 @@ def test_tda_add_sub_index(self):

def test_tda_add_dt64_object_array(self, box_df_fail, tz_naive_fixture):
# Result should be cast back to DatetimeArray
box = box_df_fail
dti = pd.date_range("2016-01-01", periods=3, tz=tz_naive_fixture)
dti = dti._with_freq(None)
tdi = dti - dti

obj = tm.box_expected(tdi, box_df_fail)
other = tm.box_expected(dti, box_df_fail)
obj = tm.box_expected(tdi, box)
other = tm.box_expected(dti, box)

warn = PerformanceWarning if box_df_fail is not pd.DataFrame else None
warn = PerformanceWarning if box is not pd.DataFrame else None
with tm.assert_produces_warning(warn):
result = obj + other.astype(object)
tm.assert_equal(result, other)
Expand Down Expand Up @@ -1195,16 +1196,19 @@ def test_td64arr_sub_td64_array(self, box_with_array):
result = tdarr - tdi
tm.assert_equal(result, expected)

def test_td64arr_add_sub_tdi(self, box, names):
def test_td64arr_add_sub_tdi(self, box_with_array, names):
# GH#17250 make sure result dtype is correct
# GH#19043 make sure names are propagated correctly
box = box_with_array

if box is pd.DataFrame and names[1] != names[0]:
pytest.skip(
"Name propagation for DataFrame does not behave like "
"it does for Index/Series"
)

tdi = TimedeltaIndex(["0 days", "1 day"], name=names[0])
tdi = np.array(tdi) if box is tm.to_array else tdi
ser = Series([Timedelta(hours=3), Timedelta(hours=4)], name=names[1])
expected = Series(
[Timedelta(hours=3), Timedelta(days=1, hours=4)], name=names[2]
Expand Down Expand Up @@ -1299,8 +1303,10 @@ def test_td64arr_sub_timedeltalike(self, two_hours, box_with_array):
# ------------------------------------------------------------------
# __add__/__sub__ with DateOffsets and arrays of DateOffsets

def test_td64arr_add_offset_index(self, names, box):
def test_td64arr_add_offset_index(self, names, box_with_array):
# GH#18849, GH#19744
box = box_with_array

if box is pd.DataFrame and names[1] != names[0]:
pytest.skip(
"Name propagation for DataFrame does not behave like "
Expand All @@ -1309,6 +1315,7 @@ def test_td64arr_add_offset_index(self, names, box):

tdi = TimedeltaIndex(["1 days 00:00:00", "3 days 04:00:00"], name=names[0])
other = pd.Index([pd.offsets.Hour(n=1), pd.offsets.Minute(n=-2)], name=names[1])
other = np.array(other) if box is tm.to_array else other

expected = TimedeltaIndex(
[tdi[n] + other[n] for n in range(len(tdi))], freq="infer", name=names[2]
Expand Down Expand Up @@ -1347,16 +1354,13 @@ def test_td64arr_add_offset_array(self, box_with_array):
res2 = other + tdi
tm.assert_equal(res2, expected)

@pytest.mark.parametrize(
"names", [(None, None, None), ("foo", "bar", None), ("foo", "foo", "foo")]
)
def test_td64arr_sub_offset_index(self, names, box_with_array):
# GH#18824, GH#19744
box = box_with_array
xbox = box if box is not tm.to_array else pd.Index
exname = names[2] if box is not tm.to_array else names[1]

if box is pd.DataFrame and names[1] == "bar":
if box is pd.DataFrame and names[1] != names[0]:
pytest.skip(
"Name propagation for DataFrame does not behave like "
"it does for Index/Series"
Expand Down Expand Up @@ -1392,9 +1396,6 @@ def test_td64arr_sub_offset_array(self, box_with_array):
res = tdi - other
tm.assert_equal(res, expected)

@pytest.mark.parametrize(
"names", [(None, None, None), ("foo", "bar", None), ("foo", "foo", "foo")]
)
def test_td64arr_with_offset_series(self, names, box_df_fail):
# GH#18849
box = box_df_fail
Expand Down Expand Up @@ -2030,9 +2031,13 @@ def test_td64arr_div_numeric_array(self, box_with_array, vector, any_real_dtype)
with pytest.raises(TypeError, match=pattern):
vector.astype(object) / tdser

def test_td64arr_mul_int_series(self, box_df_fail, names):
def test_td64arr_mul_int_series(self, box_with_array, names, request):
# GH#19042 test for correct name attachment
box = box_df_fail # broadcasts along wrong axis, but doesn't raise
box = box_with_array
if box_with_array is pd.DataFrame and names[2] is None:
reason = "broadcasts along wrong axis, but doesn't raise"
request.node.add_marker(pytest.mark.xfail(reason=reason))

exname = names[2] if box is not tm.to_array else names[1]

tdi = TimedeltaIndex(
Expand All @@ -2056,7 +2061,10 @@ def test_td64arr_mul_int_series(self, box_df_fail, names):

# The direct operation tdi * ser still needs to be fixed.
result = ser.__rmul__(tdi)
tm.assert_equal(result, expected)
if box is pd.DataFrame:
assert result is NotImplemented
else:
tm.assert_equal(result, expected)

# TODO: Should we be parametrizing over types for `ser` too?
def test_float_series_rdiv_td64arr(self, box_with_array, names):
Expand Down
10 changes: 8 additions & 2 deletions pandas/tests/extension/base/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ def check_opname(self, s, op_name, other, exc=Exception):
def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
if exc is None:
result = op(s, other)
expected = s.combine(other, op)
self.assert_series_equal(result, expected)
if isinstance(s, pd.DataFrame):
if len(s.columns) != 1:
raise NotImplementedError
expected = s.iloc[:, 0].combine(other, op).to_frame()
self.assert_frame_equal(result, expected)
else:
expected = s.combine(other, op)
self.assert_series_equal(result, expected)
else:
with pytest.raises(exc):
op(s, other)
Expand Down
12 changes: 11 additions & 1 deletion pandas/tests/extension/test_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ class TestMissing(base.BaseMissingTests):


class TestArithmeticOps(base.BaseArithmeticOpsTests):
implements = {"__sub__", "__rsub__"}

def check_opname(self, s, op_name, other, exc=None):
# overwriting to indicate ops don't raise an error
super().check_opname(s, op_name, other, exc=None)

def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
if exc is None:
if op_name in ("__sub__", "__rsub__"):
if op_name in self.implements:
# subtraction for bools raises TypeError (but not yet in 1.13)
if _np_version_under1p14:
pytest.skip("__sub__ does not yet raise in numpy 1.13")
Expand Down Expand Up @@ -151,6 +153,14 @@ def test_error(self, data, all_arithmetic_operators):
# other specific errors tested in the boolean array specific tests
pass

def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
# frame & scalar
op_name = all_arithmetic_operators
if op_name in self.implements:
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
else:
pytest.xfail("_reduce needs implementation")


class TestComparisonOps(base.BaseComparisonOpsTests):
def check_opname(self, s, op_name, other, exc=None):
Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/extension/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ def test_consistent_casting(self, dtype, expected):


class TestArithmeticOps(base.BaseArithmeticOpsTests):
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
# frame & scalar
op_name = all_arithmetic_operators
if op_name != "__rmod__":
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
else:
pytest.skip("rmod never called when string is first argument")

def test_arith_series_with_scalar(self, data, all_arithmetic_operators):

op_name = all_arithmetic_operators
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/extension/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ def test_array_interface(self, data):
class TestArithmeticOps(BaseDatetimeTests, base.BaseArithmeticOpsTests):
implements = {"__sub__", "__rsub__"}

def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
# frame & scalar
if all_arithmetic_operators in self.implements:
df = pd.DataFrame({"A": data})
self.check_opname(df, all_arithmetic_operators, data[0], exc=None)
else:
# ... but not the rest.
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)

def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
if all_arithmetic_operators in self.implements:
s = pd.Series(data)
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/extension/test_period.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ class TestInterface(BasePeriodTests, base.BaseInterfaceTests):
class TestArithmeticOps(BasePeriodTests, base.BaseArithmeticOpsTests):
implements = {"__sub__", "__rsub__"}

def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
# frame & scalar
if all_arithmetic_operators in self.implements:
df = pd.DataFrame({"A": data})
self.check_opname(df, all_arithmetic_operators, data[0], exc=None)
else:
# ... but not the rest.
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)

def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
# we implement substitution...
if all_arithmetic_operators in self.implements:
Expand Down
13 changes: 1 addition & 12 deletions pandas/tests/frame/test_cumulative.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
"""

import numpy as np
import pytest

from pandas import DataFrame, Series, _is_numpy_dev
from pandas import DataFrame, Series
import pandas._testing as tm


Expand Down Expand Up @@ -74,11 +73,6 @@ def test_cumprod(self, datetime_frame):
df.cumprod(0)
df.cumprod(1)

@pytest.mark.xfail(
_is_numpy_dev,
reason="https://github.com/pandas-dev/pandas/issues/31992",
strict=False,
)
def test_cummin(self, datetime_frame):
datetime_frame.iloc[5:10, 0] = np.nan
datetime_frame.iloc[10:15, 1] = np.nan
Expand All @@ -102,11 +96,6 @@ def test_cummin(self, datetime_frame):
cummin_xs = datetime_frame.cummin(axis=1)
assert np.shape(cummin_xs) == np.shape(datetime_frame)

@pytest.mark.xfail(
_is_numpy_dev,
reason="https://github.com/pandas-dev/pandas/issues/31992",
strict=False,
)
def test_cummax(self, datetime_frame):
datetime_frame.iloc[5:10, 0] = np.nan
datetime_frame.iloc[10:15, 1] = np.nan
Expand Down
8 changes: 6 additions & 2 deletions pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pytest

from pandas.compat import PY37
from pandas.compat import PY37, is_platform_windows

import pandas as pd
from pandas import (
Expand All @@ -13,6 +13,7 @@
Index,
MultiIndex,
Series,
_np_version_under1p17,
qcut,
)
import pandas._testing as tm
Expand Down Expand Up @@ -210,7 +211,10 @@ def test_level_get_group(observed):

# GH#21636 flaky on py37; may be related to older numpy, see discussion
# https://github.com/MacPython/pandas-wheels/pull/64
@pytest.mark.xfail(PY37, reason="Flaky, GH-27902", strict=False)
@pytest.mark.xfail(
PY37 and _np_version_under1p17 and not is_platform_windows(),
reason="Flaky, GH-27902",
)
@pytest.mark.parametrize("ordered", [True, False])
def test_apply(ordered):
# GH 10138
Expand Down
10 changes: 6 additions & 4 deletions pandas/tests/io/parser/test_usecols.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,13 @@ def test_raises_on_usecols_names_mismatch(all_parsers, usecols, kwargs, expected
tm.assert_frame_equal(result, expected)


@pytest.mark.xfail(
reason="see gh-16469: works on the C engine but not the Python engine", strict=False
)
@pytest.mark.parametrize("usecols", [["A", "C"], [0, 2]])
def test_usecols_subset_names_mismatch_orig_columns(all_parsers, usecols):
def test_usecols_subset_names_mismatch_orig_columns(all_parsers, usecols, request):
if all_parsers.engine != "c":
reason = "see gh-16469: works on the C engine but not the Python engine"
# Number of passed names did not match number of header fields in the file
request.node.add_marker(pytest.mark.xfail(reason=reason, raises=ValueError))

data = "a,b,c,d\n1,2,3,4\n5,6,7,8"
names = ["A", "B", "C", "D"]
parser = all_parsers
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/scalar/timedelta/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ def test_td_div_numeric_scalar(self):
_is_numpy_dev,
raises=RuntimeWarning,
reason="https://github.com/pandas-dev/pandas/issues/31992",
strict=False,
),
),
float("nan"),
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/series/test_cumulative.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import pytest

import pandas as pd
from pandas import _is_numpy_dev
import pandas._testing as tm


Expand All @@ -38,11 +37,6 @@ def test_cumsum(self, datetime_series):
def test_cumprod(self, datetime_series):
_check_accum_op("cumprod", datetime_series)

@pytest.mark.xfail(
_is_numpy_dev,
reason="https://github.com/pandas-dev/pandas/issues/31992",
strict=False,
)
def test_cummin(self, datetime_series):
tm.assert_numpy_array_equal(
datetime_series.cummin().values,
Expand All @@ -56,11 +50,6 @@ def test_cummin(self, datetime_series):
result.index = result.index._with_freq(None)
tm.assert_series_equal(result, expected)

@pytest.mark.xfail(
_is_numpy_dev,
reason="https://github.com/pandas-dev/pandas/issues/31992",
strict=False,
)
def test_cummax(self, datetime_series):
tm.assert_numpy_array_equal(
datetime_series.cummax().values,
Expand Down
Loading