Skip to content

Commit 3ee9000

Browse files
authored
TST: de-xfail, remove strict=False (#33854)
1 parent 31d0034 commit 3ee9000

15 files changed

+105
-74
lines changed

pandas/tests/arithmetic/test_datetime64.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@ def test_dti_cmp_nat_behaves_like_float_cmp_nan(self):
527527
"op",
528528
[operator.eq, operator.ne, operator.gt, operator.ge, operator.lt, operator.le],
529529
)
530-
def test_comparison_tzawareness_compat(self, op, box_df_fail):
530+
def test_comparison_tzawareness_compat(self, op, box_with_array):
531531
# GH#18162
532-
box = box_df_fail
532+
box = box_with_array
533533

534534
dr = pd.date_range("2016-01-01", periods=6)
535535
dz = dr.tz_localize("US/Pacific")
@@ -541,34 +541,35 @@ def test_comparison_tzawareness_compat(self, op, box_df_fail):
541541
with pytest.raises(TypeError, match=msg):
542542
op(dr, dz)
543543

544-
# FIXME: DataFrame case fails to raise for == and !=, wrong
545-
# message for inequalities
544+
if box is pd.DataFrame:
545+
tolist = lambda x: x.astype(object).values.tolist()[0]
546+
else:
547+
tolist = list
548+
546549
with pytest.raises(TypeError, match=msg):
547-
op(dr, list(dz))
550+
op(dr, tolist(dz))
548551
with pytest.raises(TypeError, match=msg):
549-
op(dr, np.array(list(dz), dtype=object))
552+
op(dr, np.array(tolist(dz), dtype=object))
550553
with pytest.raises(TypeError, match=msg):
551554
op(dz, dr)
552555

553-
# FIXME: DataFrame case fails to raise for == and !=, wrong
554-
# message for inequalities
555556
with pytest.raises(TypeError, match=msg):
556-
op(dz, list(dr))
557+
op(dz, tolist(dr))
557558
with pytest.raises(TypeError, match=msg):
558-
op(dz, np.array(list(dr), dtype=object))
559+
op(dz, np.array(tolist(dr), dtype=object))
559560

560561
# The aware==aware and naive==naive comparisons should *not* raise
561562
assert np.all(dr == dr)
562-
assert np.all(dr == list(dr))
563-
assert np.all(list(dr) == dr)
564-
assert np.all(np.array(list(dr), dtype=object) == dr)
565-
assert np.all(dr == np.array(list(dr), dtype=object))
563+
assert np.all(dr == tolist(dr))
564+
assert np.all(tolist(dr) == dr)
565+
assert np.all(np.array(tolist(dr), dtype=object) == dr)
566+
assert np.all(dr == np.array(tolist(dr), dtype=object))
566567

567568
assert np.all(dz == dz)
568-
assert np.all(dz == list(dz))
569-
assert np.all(list(dz) == dz)
570-
assert np.all(np.array(list(dz), dtype=object) == dz)
571-
assert np.all(dz == np.array(list(dz), dtype=object))
569+
assert np.all(dz == tolist(dz))
570+
assert np.all(tolist(dz) == dz)
571+
assert np.all(np.array(tolist(dz), dtype=object) == dz)
572+
assert np.all(dz == np.array(tolist(dz), dtype=object))
572573

573574
@pytest.mark.parametrize(
574575
"op",

pandas/tests/arithmetic/test_timedelta64.py

+23-15
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,15 @@ def test_tda_add_sub_index(self):
543543

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

550-
obj = tm.box_expected(tdi, box_df_fail)
551-
other = tm.box_expected(dti, box_df_fail)
551+
obj = tm.box_expected(tdi, box)
552+
other = tm.box_expected(dti, box)
552553

553-
warn = PerformanceWarning if box_df_fail is not pd.DataFrame else None
554+
warn = PerformanceWarning if box is not pd.DataFrame else None
554555
with tm.assert_produces_warning(warn):
555556
result = obj + other.astype(object)
556557
tm.assert_equal(result, other)
@@ -1195,16 +1196,19 @@ def test_td64arr_sub_td64_array(self, box_with_array):
11951196
result = tdarr - tdi
11961197
tm.assert_equal(result, expected)
11971198

1198-
def test_td64arr_add_sub_tdi(self, box, names):
1199+
def test_td64arr_add_sub_tdi(self, box_with_array, names):
11991200
# GH#17250 make sure result dtype is correct
12001201
# GH#19043 make sure names are propagated correctly
1202+
box = box_with_array
1203+
12011204
if box is pd.DataFrame and names[1] != names[0]:
12021205
pytest.skip(
12031206
"Name propagation for DataFrame does not behave like "
12041207
"it does for Index/Series"
12051208
)
12061209

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

1302-
def test_td64arr_add_offset_index(self, names, box):
1306+
def test_td64arr_add_offset_index(self, names, box_with_array):
13031307
# GH#18849, GH#19744
1308+
box = box_with_array
1309+
13041310
if box is pd.DataFrame and names[1] != names[0]:
13051311
pytest.skip(
13061312
"Name propagation for DataFrame does not behave like "
@@ -1309,6 +1315,7 @@ def test_td64arr_add_offset_index(self, names, box):
13091315

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

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

1350-
@pytest.mark.parametrize(
1351-
"names", [(None, None, None), ("foo", "bar", None), ("foo", "foo", "foo")]
1352-
)
13531357
def test_td64arr_sub_offset_index(self, names, box_with_array):
13541358
# GH#18824, GH#19744
13551359
box = box_with_array
13561360
xbox = box if box is not tm.to_array else pd.Index
13571361
exname = names[2] if box is not tm.to_array else names[1]
13581362

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

1395-
@pytest.mark.parametrize(
1396-
"names", [(None, None, None), ("foo", "bar", None), ("foo", "foo", "foo")]
1397-
)
13981399
def test_td64arr_with_offset_series(self, names, box_df_fail):
13991400
# GH#18849
14001401
box = box_df_fail
@@ -2030,9 +2031,13 @@ def test_td64arr_div_numeric_array(self, box_with_array, vector, any_real_dtype)
20302031
with pytest.raises(TypeError, match=pattern):
20312032
vector.astype(object) / tdser
20322033

2033-
def test_td64arr_mul_int_series(self, box_df_fail, names):
2034+
def test_td64arr_mul_int_series(self, box_with_array, names, request):
20342035
# GH#19042 test for correct name attachment
2035-
box = box_df_fail # broadcasts along wrong axis, but doesn't raise
2036+
box = box_with_array
2037+
if box_with_array is pd.DataFrame and names[2] is None:
2038+
reason = "broadcasts along wrong axis, but doesn't raise"
2039+
request.node.add_marker(pytest.mark.xfail(reason=reason))
2040+
20362041
exname = names[2] if box is not tm.to_array else names[1]
20372042

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

20572062
# The direct operation tdi * ser still needs to be fixed.
20582063
result = ser.__rmul__(tdi)
2059-
tm.assert_equal(result, expected)
2064+
if box is pd.DataFrame:
2065+
assert result is NotImplemented
2066+
else:
2067+
tm.assert_equal(result, expected)
20602068

20612069
# TODO: Should we be parametrizing over types for `ser` too?
20622070
def test_float_series_rdiv_td64arr(self, box_with_array, names):

pandas/tests/extension/base/ops.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ def check_opname(self, s, op_name, other, exc=Exception):
2929
def _check_op(self, s, op, other, op_name, exc=NotImplementedError):
3030
if exc is None:
3131
result = op(s, other)
32-
expected = s.combine(other, op)
33-
self.assert_series_equal(result, expected)
32+
if isinstance(s, pd.DataFrame):
33+
if len(s.columns) != 1:
34+
raise NotImplementedError
35+
expected = s.iloc[:, 0].combine(other, op).to_frame()
36+
self.assert_frame_equal(result, expected)
37+
else:
38+
expected = s.combine(other, op)
39+
self.assert_series_equal(result, expected)
3440
else:
3541
with pytest.raises(exc):
3642
op(s, other)

pandas/tests/extension/test_boolean.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,15 @@ class TestMissing(base.BaseMissingTests):
102102

103103

104104
class TestArithmeticOps(base.BaseArithmeticOpsTests):
105+
implements = {"__sub__", "__rsub__"}
106+
105107
def check_opname(self, s, op_name, other, exc=None):
106108
# overwriting to indicate ops don't raise an error
107109
super().check_opname(s, op_name, other, exc=None)
108110

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

156+
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
157+
# frame & scalar
158+
op_name = all_arithmetic_operators
159+
if op_name in self.implements:
160+
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
161+
else:
162+
pytest.xfail("_reduce needs implementation")
163+
154164

155165
class TestComparisonOps(base.BaseComparisonOpsTests):
156166
def check_opname(self, s, op_name, other, exc=None):

pandas/tests/extension/test_categorical.py

+8
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ def test_consistent_casting(self, dtype, expected):
203203

204204

205205
class TestArithmeticOps(base.BaseArithmeticOpsTests):
206+
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
207+
# frame & scalar
208+
op_name = all_arithmetic_operators
209+
if op_name != "__rmod__":
210+
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
211+
else:
212+
pytest.skip("rmod never called when string is first argument")
213+
206214
def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
207215

208216
op_name = all_arithmetic_operators

pandas/tests/extension/test_datetime.py

+9
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ def test_array_interface(self, data):
111111
class TestArithmeticOps(BaseDatetimeTests, base.BaseArithmeticOpsTests):
112112
implements = {"__sub__", "__rsub__"}
113113

114+
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
115+
# frame & scalar
116+
if all_arithmetic_operators in self.implements:
117+
df = pd.DataFrame({"A": data})
118+
self.check_opname(df, all_arithmetic_operators, data[0], exc=None)
119+
else:
120+
# ... but not the rest.
121+
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
122+
114123
def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
115124
if all_arithmetic_operators in self.implements:
116125
s = pd.Series(data)

pandas/tests/extension/test_period.py

+9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ class TestInterface(BasePeriodTests, base.BaseInterfaceTests):
8484
class TestArithmeticOps(BasePeriodTests, base.BaseArithmeticOpsTests):
8585
implements = {"__sub__", "__rsub__"}
8686

87+
def test_arith_frame_with_scalar(self, data, all_arithmetic_operators):
88+
# frame & scalar
89+
if all_arithmetic_operators in self.implements:
90+
df = pd.DataFrame({"A": data})
91+
self.check_opname(df, all_arithmetic_operators, data[0], exc=None)
92+
else:
93+
# ... but not the rest.
94+
super().test_arith_frame_with_scalar(data, all_arithmetic_operators)
95+
8796
def test_arith_series_with_scalar(self, data, all_arithmetic_operators):
8897
# we implement substitution...
8998
if all_arithmetic_operators in self.implements:

pandas/tests/frame/test_cumulative.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
"""
88

99
import numpy as np
10-
import pytest
1110

12-
from pandas import DataFrame, Series, _is_numpy_dev
11+
from pandas import DataFrame, Series
1312
import pandas._testing as tm
1413

1514

@@ -74,11 +73,6 @@ def test_cumprod(self, datetime_frame):
7473
df.cumprod(0)
7574
df.cumprod(1)
7675

77-
@pytest.mark.xfail(
78-
_is_numpy_dev,
79-
reason="https://github.com/pandas-dev/pandas/issues/31992",
80-
strict=False,
81-
)
8276
def test_cummin(self, datetime_frame):
8377
datetime_frame.iloc[5:10, 0] = np.nan
8478
datetime_frame.iloc[10:15, 1] = np.nan
@@ -102,11 +96,6 @@ def test_cummin(self, datetime_frame):
10296
cummin_xs = datetime_frame.cummin(axis=1)
10397
assert np.shape(cummin_xs) == np.shape(datetime_frame)
10498

105-
@pytest.mark.xfail(
106-
_is_numpy_dev,
107-
reason="https://github.com/pandas-dev/pandas/issues/31992",
108-
strict=False,
109-
)
11099
def test_cummax(self, datetime_frame):
111100
datetime_frame.iloc[5:10, 0] = np.nan
112101
datetime_frame.iloc[10:15, 1] = np.nan

pandas/tests/groupby/test_categorical.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import pytest
55

6-
from pandas.compat import PY37
6+
from pandas.compat import PY37, is_platform_windows
77

88
import pandas as pd
99
from pandas import (
@@ -13,6 +13,7 @@
1313
Index,
1414
MultiIndex,
1515
Series,
16+
_np_version_under1p17,
1617
qcut,
1718
)
1819
import pandas._testing as tm
@@ -210,7 +211,10 @@ def test_level_get_group(observed):
210211

211212
# GH#21636 flaky on py37; may be related to older numpy, see discussion
212213
# https://github.com/MacPython/pandas-wheels/pull/64
213-
@pytest.mark.xfail(PY37, reason="Flaky, GH-27902", strict=False)
214+
@pytest.mark.xfail(
215+
PY37 and _np_version_under1p17 and not is_platform_windows(),
216+
reason="Flaky, GH-27902",
217+
)
214218
@pytest.mark.parametrize("ordered", [True, False])
215219
def test_apply(ordered):
216220
# GH 10138

pandas/tests/io/parser/test_usecols.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -558,11 +558,13 @@ def test_raises_on_usecols_names_mismatch(all_parsers, usecols, kwargs, expected
558558
tm.assert_frame_equal(result, expected)
559559

560560

561-
@pytest.mark.xfail(
562-
reason="see gh-16469: works on the C engine but not the Python engine", strict=False
563-
)
564561
@pytest.mark.parametrize("usecols", [["A", "C"], [0, 2]])
565-
def test_usecols_subset_names_mismatch_orig_columns(all_parsers, usecols):
562+
def test_usecols_subset_names_mismatch_orig_columns(all_parsers, usecols, request):
563+
if all_parsers.engine != "c":
564+
reason = "see gh-16469: works on the C engine but not the Python engine"
565+
# Number of passed names did not match number of header fields in the file
566+
request.node.add_marker(pytest.mark.xfail(reason=reason, raises=ValueError))
567+
566568
data = "a,b,c,d\n1,2,3,4\n5,6,7,8"
567569
names = ["A", "B", "C", "D"]
568570
parser = all_parsers

pandas/tests/scalar/timedelta/test_arithmetic.py

-1
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ def test_td_div_numeric_scalar(self):
419419
_is_numpy_dev,
420420
raises=RuntimeWarning,
421421
reason="https://github.com/pandas-dev/pandas/issues/31992",
422-
strict=False,
423422
),
424423
),
425424
float("nan"),

pandas/tests/series/test_cumulative.py

-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import pytest
1212

1313
import pandas as pd
14-
from pandas import _is_numpy_dev
1514
import pandas._testing as tm
1615

1716

@@ -38,11 +37,6 @@ def test_cumsum(self, datetime_series):
3837
def test_cumprod(self, datetime_series):
3938
_check_accum_op("cumprod", datetime_series)
4039

41-
@pytest.mark.xfail(
42-
_is_numpy_dev,
43-
reason="https://github.com/pandas-dev/pandas/issues/31992",
44-
strict=False,
45-
)
4640
def test_cummin(self, datetime_series):
4741
tm.assert_numpy_array_equal(
4842
datetime_series.cummin().values,
@@ -56,11 +50,6 @@ def test_cummin(self, datetime_series):
5650
result.index = result.index._with_freq(None)
5751
tm.assert_series_equal(result, expected)
5852

59-
@pytest.mark.xfail(
60-
_is_numpy_dev,
61-
reason="https://github.com/pandas-dev/pandas/issues/31992",
62-
strict=False,
63-
)
6453
def test_cummax(self, datetime_series):
6554
tm.assert_numpy_array_equal(
6655
datetime_series.cummax().values,

0 commit comments

Comments
 (0)