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
Changes from 1 commit
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
32 changes: 32 additions & 0 deletions pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,35 @@ def test_series_indexing_zerodim_np_array(self):
s = Series([1, 2])
result = s.loc[np.array(0)]
assert result == 1

def test_PeriodIndex_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_TimedeltaIndex_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_PeriodIndex_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)

def test_TimedeltaIndex_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)