Skip to content

Commit cd484cc

Browse files
jbrockmendeljreback
authored andcommitted
move shift_months test to test_arithmetic (#19636)
1 parent c0e75a5 commit cd484cc

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

pandas/tests/indexes/datetimes/test_arithmetic.py

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
DatetimeIndex, TimedeltaIndex,
1616
date_range)
1717
from pandas._libs import tslib
18+
from pandas._libs.tslibs.offsets import shift_months
1819

1920

2021
@pytest.fixture(params=[None, 'UTC', 'Asia/Tokyo',
@@ -933,3 +934,19 @@ def test_datetime64_with_DateOffset(klass, assert_func):
933934
Timestamp('2000-02-29', tz='US/Central')], name='a')
934935
assert_func(result, exp)
935936
assert_func(result2, exp)
937+
938+
939+
@pytest.mark.parametrize('years', [-1, 0, 1])
940+
@pytest.mark.parametrize('months', [-2, 0, 2])
941+
def test_shift_months(years, months):
942+
s = DatetimeIndex([Timestamp('2000-01-05 00:15:00'),
943+
Timestamp('2000-01-31 00:23:00'),
944+
Timestamp('2000-01-01'),
945+
Timestamp('2000-02-29'),
946+
Timestamp('2000-12-31')])
947+
actual = DatetimeIndex(shift_months(s.asi8, years * 12 + months))
948+
949+
raw = [x + pd.offsets.DateOffset(years=years, months=months)
950+
for x in s]
951+
expected = DatetimeIndex(raw)
952+
tm.assert_index_equal(actual, expected)

pandas/tests/indexes/datetimes/test_ops.py

-15
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
import numpy as np
66
from datetime import datetime
77

8-
from itertools import product
98
import pandas as pd
109
import pandas._libs.tslib as tslib
11-
from pandas._libs.tslibs.offsets import shift_months
1210
import pandas.util.testing as tm
1311
from pandas import (DatetimeIndex, PeriodIndex, Series, Timestamp,
1412
date_range, _np_version_under1p10, Index,
@@ -568,19 +566,6 @@ def test_equals(self):
568566
assert not idx.equals(pd.Series(idx3))
569567

570568

571-
@pytest.mark.parametrize('years,months', product([-1, 0, 1], [-2, 0, 2]))
572-
def test_shift_months(years, months):
573-
s = DatetimeIndex([Timestamp('2000-01-05 00:15:00'),
574-
Timestamp('2000-01-31 00:23:00'),
575-
Timestamp('2000-01-01'),
576-
Timestamp('2000-02-29'),
577-
Timestamp('2000-12-31')])
578-
actual = DatetimeIndex(shift_months(s.asi8, years * 12 + months))
579-
expected = DatetimeIndex([x + pd.offsets.DateOffset(
580-
years=years, months=months) for x in s])
581-
tm.assert_index_equal(actual, expected)
582-
583-
584569
class TestBusinessDatetimeIndex(object):
585570

586571
def setup_method(self, method):

0 commit comments

Comments
 (0)