Skip to content

Commit 052bb17

Browse files
committed
STYLE/DEPR: catch PerformanceWarnings
closes pandas-dev#18989
1 parent c24a0d2 commit 052bb17

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
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

0 commit comments

Comments
 (0)