Skip to content

Commit 58e8ee2

Browse files
authored
TST: limit printing of xfail cases & catch Performance Warnings (#19001)
closes #18989
1 parent e92d788 commit 58e8ee2

File tree

4 files changed

+65
-24
lines changed

4 files changed

+65
-24
lines changed

pandas/tests/indexes/datetimes/test_arithmetic.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,25 @@ def test_dti_add_offset_array(self, tz, box):
368368
# GH#18849
369369
dti = pd.date_range('2017-01-01', periods=2, tz=tz)
370370
other = box([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)])
371-
res = dti + other
371+
372+
with tm.assert_produces_warning(PerformanceWarning):
373+
res = dti + other
372374
expected = DatetimeIndex([dti[n] + other[n] for n in range(len(dti))],
373375
name=dti.name, freq='infer')
374376
tm.assert_index_equal(res, expected)
375377

376-
res2 = other + dti
378+
with tm.assert_produces_warning(PerformanceWarning):
379+
res2 = other + dti
377380
tm.assert_index_equal(res2, expected)
378381

379382
@pytest.mark.parametrize('box', [np.array, pd.Index])
380383
def test_dti_sub_offset_array(self, tz, box):
381384
# GH#18824
382385
dti = pd.date_range('2017-01-01', periods=2, tz=tz)
383386
other = box([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)])
384-
res = dti - other
387+
388+
with tm.assert_produces_warning(PerformanceWarning):
389+
res = dti - other
385390
expected = DatetimeIndex([dti[n] - other[n] for n in range(len(dti))],
386391
name=dti.name, freq='infer')
387392
tm.assert_index_equal(res, expected)
@@ -392,20 +397,25 @@ def test_dti_sub_offset_array(self, tz, box):
392397
def test_dti_with_offset_series(self, tz, names):
393398
# GH#18849
394399
dti = pd.date_range('2017-01-01', periods=2, tz=tz, name=names[0])
395-
other = pd.Series([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)],
396-
name=names[1])
400+
other = Series([pd.offsets.MonthEnd(), pd.offsets.Day(n=2)],
401+
name=names[1])
397402

398-
expected_add = pd.Series([dti[n] + other[n] for n in range(len(dti))],
399-
name=names[2])
400-
res = dti + other
403+
expected_add = Series([dti[n] + other[n] for n in range(len(dti))],
404+
name=names[2])
405+
406+
with tm.assert_produces_warning(PerformanceWarning):
407+
res = dti + other
401408
tm.assert_series_equal(res, expected_add)
402-
res2 = other + dti
409+
410+
with tm.assert_produces_warning(PerformanceWarning):
411+
res2 = other + dti
403412
tm.assert_series_equal(res2, expected_add)
404413

405-
expected_sub = pd.Series([dti[n] - other[n] for n in range(len(dti))],
406-
name=names[2])
414+
expected_sub = Series([dti[n] - other[n] for n in range(len(dti))],
415+
name=names[2])
407416

408-
res3 = dti - other
417+
with tm.assert_produces_warning(PerformanceWarning):
418+
res3 = dti - other
409419
tm.assert_series_equal(res3, expected_sub)
410420

411421

pandas/tests/indexing/test_coercion.py

+35-2
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,8 @@ def test_replace_series(self, how, to_key, from_key):
819819
assert obj.dtype == from_key
820820

821821
if (from_key.startswith('datetime') and to_key.startswith('datetime')):
822-
pytest.xfail("different tz, currently mask_missing "
823-
"raises SystemError")
822+
# tested below
823+
return
824824

825825
if how == 'dict':
826826
replacer = dict(zip(self.rep[from_key], self.rep[to_key]))
@@ -849,5 +849,38 @@ def test_replace_series(self, how, to_key, from_key):
849849

850850
tm.assert_series_equal(result, exp)
851851

852+
# TODO(jreback) commented out to only have a single xfail printed
853+
@pytest.mark.xfail(reason="different tz, "
854+
"currently mask_missing raises SystemError")
855+
# @pytest.mark.parametrize('how', ['dict', 'series'])
856+
# @pytest.mark.parametrize('to_key', [
857+
# 'datetime64[ns]', 'datetime64[ns, UTC]',
858+
# 'datetime64[ns, US/Eastern]'])
859+
# @pytest.mark.parametrize('from_key', [
860+
# 'datetime64[ns]', 'datetime64[ns, UTC]',
861+
# 'datetime64[ns, US/Eastern]'])
862+
# def test_replace_series_datetime_datetime(self, how, to_key, from_key):
863+
def test_replace_series_datetime_datetime(self):
864+
how = 'dict'
865+
to_key = 'datetime64[ns]'
866+
from_key = 'datetime64[ns]'
867+
868+
index = pd.Index([3, 4], name='xxx')
869+
obj = pd.Series(self.rep[from_key], index=index, name='yyy')
870+
assert obj.dtype == from_key
871+
872+
if how == 'dict':
873+
replacer = dict(zip(self.rep[from_key], self.rep[to_key]))
874+
elif how == 'series':
875+
replacer = pd.Series(self.rep[to_key], index=self.rep[from_key])
876+
else:
877+
raise ValueError
878+
879+
result = obj.replace(replacer)
880+
exp = pd.Series(self.rep[to_key], index=index, name='yyy')
881+
assert exp.dtype == to_key
882+
883+
tm.assert_series_equal(result, exp)
884+
852885
def test_replace_series_period(self):
853886
pass

pandas/tests/series/test_rank.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,9 @@ def test_rank_signature(self):
209209
pytest.param([np.iinfo(np.int64).min, -100, 0, 1, 9999, 100000,
210210
1e10, np.iinfo(np.int64).max],
211211
'int64',
212-
marks=pytest.mark.xfail(reason='''iNaT is equivalent to
213-
minimum value of dtype
214-
int64 pending issue
215-
#16674'''),
216-
),
212+
marks=pytest.mark.xfail(
213+
reason="iNaT is equivalent to minimum value of dtype"
214+
"int64 pending issue #16674")),
217215
([NegInfinity(), '1', 'A', 'BA', 'Ba', 'C', Infinity()],
218216
'object')
219217
])

pandas/tests/tseries/offsets/test_offsets.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _get_offset(self, klass, value=1, normalize=False):
113113
else:
114114
try:
115115
klass = klass(value, normalize=normalize)
116-
except:
116+
except Exception:
117117
klass = klass(normalize=normalize)
118118
return klass
119119

@@ -143,10 +143,10 @@ def test_apply_out_of_range(self, tz):
143143

144144
except tslib.OutOfBoundsDatetime:
145145
raise
146-
except (ValueError, KeyError) as e:
147-
pytest.skip(
148-
"cannot create out_of_range offset: {0} {1}".format(
149-
str(self).split('.')[-1], e))
146+
except (ValueError, KeyError):
147+
# we are creating an invalid offset
148+
# so ignore
149+
pass
150150

151151

152152
class TestCommon(Base):

0 commit comments

Comments
 (0)