diff --git a/pandas/tests/indexing/test_datetime.py b/pandas/tests/indexing/test_datetime.py index 4c865d00b3adb..d4da34cab6f5c 100644 --- a/pandas/tests/indexing/test_datetime.py +++ b/pandas/tests/indexing/test_datetime.py @@ -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) diff --git a/pandas/tests/indexing/test_timedelta.py b/pandas/tests/indexing/test_timedelta.py index 8e7a71ad3d71e..e3f5bcff4a22e 100644 --- a/pandas/tests/indexing/test_timedelta.py +++ b/pandas/tests/indexing/test_timedelta.py @@ -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)