Skip to content

move shift_months test to test_arithmetic #19636

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 1 commit into from
Feb 11, 2018
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
17 changes: 17 additions & 0 deletions pandas/tests/indexes/datetimes/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DatetimeIndex, TimedeltaIndex,
date_range)
from pandas._libs import tslib
from pandas._libs.tslibs.offsets import shift_months


@pytest.fixture(params=[None, 'UTC', 'Asia/Tokyo',
Expand Down Expand Up @@ -933,3 +934,19 @@ def test_datetime64_with_DateOffset(klass, assert_func):
Timestamp('2000-02-29', tz='US/Central')], name='a')
assert_func(result, exp)
assert_func(result2, exp)


@pytest.mark.parametrize('years', [-1, 0, 1])
@pytest.mark.parametrize('months', [-2, 0, 2])
def test_shift_months(years, months):
s = DatetimeIndex([Timestamp('2000-01-05 00:15:00'),
Timestamp('2000-01-31 00:23:00'),
Timestamp('2000-01-01'),
Timestamp('2000-02-29'),
Timestamp('2000-12-31')])
actual = DatetimeIndex(shift_months(s.asi8, years * 12 + months))

raw = [x + pd.offsets.DateOffset(years=years, months=months)
for x in s]
expected = DatetimeIndex(raw)
tm.assert_index_equal(actual, expected)
15 changes: 0 additions & 15 deletions pandas/tests/indexes/datetimes/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import numpy as np
from datetime import datetime

from itertools import product
import pandas as pd
import pandas._libs.tslib as tslib
from pandas._libs.tslibs.offsets import shift_months
import pandas.util.testing as tm
from pandas import (DatetimeIndex, PeriodIndex, Series, Timestamp,
date_range, _np_version_under1p10, Index,
Expand Down Expand Up @@ -568,19 +566,6 @@ def test_equals(self):
assert not idx.equals(pd.Series(idx3))


@pytest.mark.parametrize('years,months', product([-1, 0, 1], [-2, 0, 2]))
def test_shift_months(years, months):
s = DatetimeIndex([Timestamp('2000-01-05 00:15:00'),
Timestamp('2000-01-31 00:23:00'),
Timestamp('2000-01-01'),
Timestamp('2000-02-29'),
Timestamp('2000-12-31')])
actual = DatetimeIndex(shift_months(s.asi8, years * 12 + months))
expected = DatetimeIndex([x + pd.offsets.DateOffset(
years=years, months=months) for x in s])
tm.assert_index_equal(actual, expected)


class TestBusinessDatetimeIndex(object):

def setup_method(self, method):
Expand Down