Skip to content
Merged
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
16 changes: 16 additions & 0 deletions pandas/tests/series/methods/test_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,19 @@ def test_shift_dt64values_int_fill_deprecated(self):

expected = pd.Series([pd.Timestamp(0), ser[0]])
tm.assert_series_equal(result, expected)

@pytest.mark.parametrize("periods", [1, 2, 3, 4])
def test_shift_preserve_freqstr(self, periods):
# GH#21275
ser = pd.Series(
range(periods),
index=pd.date_range("2016-1-1 00:00:00", periods=periods, freq="H"),
)

result = ser.shift(1, "2H")

expected = pd.Series(
range(periods),
index=pd.date_range("2016-1-1 02:00:00", periods=periods, freq="H"),
)
tm.assert_series_equal(result, expected)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think assert_series_equal should be enough here since it'll check the index frequencies and dtypes