Skip to content

TST: Add missing tests for loc slicing of PeriodIndex, TimedeltaIndex #27086

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 2 commits into from Jun 28, 2019
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
16 changes: 16 additions & 0 deletions pandas/tests/indexing/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,19 @@ def test_loc_setitem_with_existing_dst(self):
columns=['value'],
dtype=object)
tm.assert_frame_equal(result, expected)

def test_loc_str_slicing(self):
ix = pd.period_range(start='2017-01-01', end='2018-01-01', freq='M')
ser = ix.to_series()
result = ser.loc[:"2017-12"]
expected = ser.iloc[:-1]

tm.assert_series_equal(result, expected)

def test_loc_label_slicing(self):
ix = pd.period_range(start='2017-01-01', end='2018-01-01', freq='M')
ser = ix.to_series()
result = ser.loc[:ix[-2]]
expected = ser.iloc[:-1]

tm.assert_series_equal(result, expected)
16 changes: 16 additions & 0 deletions pandas/tests/indexing/test_timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,19 @@ def test_roundtrip_thru_setitem(self):

assert expected == result
tm.assert_frame_equal(df, df_copy)

def test_loc_str_slicing(self):
ix = pd.timedelta_range(start='1 day', end='2 days', freq='1H')
ser = ix.to_series()
result = ser.loc[:"1 days"]
expected = ser.iloc[:-1]

tm.assert_series_equal(result, expected)

def test_loc_slicing(self):
ix = pd.timedelta_range(start='1 day', end='2 days', freq='1H')
ser = ix.to_series()
result = ser.loc[:ix[-2]]
expected = ser.iloc[:-1]

tm.assert_series_equal(result, expected)