Skip to content

REF: misplaced DTI.shift tests #32938

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
Mar 24, 2020
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
2 changes: 1 addition & 1 deletion pandas/tests/indexes/categorical/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def test_equals_categorical(self):
assert not ci.equals(CategoricalIndex(list("aabca") + [np.nan], ordered=True))
assert ci.equals(ci.copy())

def test_equals_categoridcal_unordered(self):
def test_equals_categorical_unordered(self):
# https://github.com/pandas-dev/pandas/issues/16603
a = pd.CategoricalIndex(["A"], categories=["A", "B"])
b = pd.CategoricalIndex(["A"], categories=["B", "A"])
Expand Down
46 changes: 1 addition & 45 deletions pandas/tests/indexes/datetimes/test_ops.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from datetime import datetime
import warnings

import numpy as np
import pytest
Expand All @@ -16,7 +15,7 @@
)
import pandas._testing as tm

from pandas.tseries.offsets import BDay, BMonthEnd, CDay, Day, Hour
from pandas.tseries.offsets import BDay, Day, Hour

START, END = datetime(2009, 1, 1), datetime(2010, 1, 1)

Expand Down Expand Up @@ -443,23 +442,6 @@ def test_copy(self):
repr(cp)
tm.assert_index_equal(cp, self.rng)

def test_shift(self):
shifted = self.rng.shift(5)
assert shifted[0] == self.rng[5]
assert shifted.freq == self.rng.freq

shifted = self.rng.shift(-5)
assert shifted[5] == self.rng[0]
assert shifted.freq == self.rng.freq

shifted = self.rng.shift(0)
assert shifted[0] == self.rng[0]
assert shifted.freq == self.rng.freq

rng = date_range(START, END, freq=BMonthEnd())
shifted = rng.shift(1, freq=BDay())
assert shifted[0] == rng[0] + BDay()

def test_equals(self):
assert not self.rng.equals(list(self.rng))

Expand Down Expand Up @@ -497,32 +479,6 @@ def test_copy(self):
repr(cp)
tm.assert_index_equal(cp, self.rng)

def test_shift(self):

shifted = self.rng.shift(5)
assert shifted[0] == self.rng[5]
assert shifted.freq == self.rng.freq

shifted = self.rng.shift(-5)
assert shifted[5] == self.rng[0]
assert shifted.freq == self.rng.freq

shifted = self.rng.shift(0)
assert shifted[0] == self.rng[0]
assert shifted.freq == self.rng.freq

with warnings.catch_warnings(record=True):
warnings.simplefilter("ignore", pd.errors.PerformanceWarning)
rng = date_range(START, END, freq=BMonthEnd())
shifted = rng.shift(1, freq=CDay())
assert shifted[0] == rng[0] + CDay()

def test_shift_periods(self):
# GH#22458 : argument 'n' was deprecated in favor of 'periods'
idx = pd.date_range(start=START, end=END, periods=3)
tm.assert_index_equal(idx.shift(periods=0), idx)
tm.assert_index_equal(idx.shift(0), idx)

def test_pickle_unpickle(self):
unpickled = tm.round_trip_pickle(self.rng)
assert unpickled.freq is not None
Expand Down
33 changes: 33 additions & 0 deletions pandas/tests/indexes/datetimes/test_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from pandas import DatetimeIndex, Series, date_range
import pandas._testing as tm

START, END = datetime(2009, 1, 1), datetime(2010, 1, 1)


class TestDatetimeIndexShift:

Expand Down Expand Up @@ -115,3 +117,34 @@ def test_dti_shift_near_midnight(self, shift, result_time):
result = s.shift(shift, freq="H")
expected = Series(1, index=DatetimeIndex([result_time], tz="EST"))
tm.assert_series_equal(result, expected)

def test_shift_periods(self):
# GH#22458 : argument 'n' was deprecated in favor of 'periods'
idx = pd.date_range(start=START, end=END, periods=3)
tm.assert_index_equal(idx.shift(periods=0), idx)
tm.assert_index_equal(idx.shift(0), idx)

@pytest.mark.parametrize("freq", ["B", "C"])
def test_shift_bday(self, freq):
rng = date_range(START, END, freq=freq)
shifted = rng.shift(5)
assert shifted[0] == rng[5]
assert shifted.freq == rng.freq

shifted = rng.shift(-5)
assert shifted[5] == rng[0]
assert shifted.freq == rng.freq

shifted = rng.shift(0)
assert shifted[0] == rng[0]
assert shifted.freq == rng.freq

def test_shift_bmonth(self):
rng = date_range(START, END, freq=pd.offsets.BMonthEnd())
shifted = rng.shift(1, freq=pd.offsets.BDay())
assert shifted[0] == rng[0] + pd.offsets.BDay()

rng = date_range(START, END, freq=pd.offsets.BMonthEnd())
with tm.assert_produces_warning(pd.errors.PerformanceWarning):
shifted = rng.shift(1, freq=pd.offsets.CDay())
assert shifted[0] == rng[0] + pd.offsets.CDay()