def test_str_label_slicing_with_negative_step(self, idx): SLC = pd.IndexSlice idx = Index(idx) ser = Series(np.arange(20), index=idx) tm.assert_indexing_slices_equivalent(ser, SLC[idx[9] :: -1], SLC[9::-1]) tm.assert_indexing_slices_equivalent(ser, SLC[: idx[9] : -1], SLC[:8:-1]) tm.assert_indexing_slices_equivalent( ser, SLC[idx[13] : idx[9] : -1], SLC[13:8:-1] ) tm.assert_indexing_slices_equivalent(ser, SLC[idx[9] : idx[13] : -1], SLC[:0])
def test_slice_with_negative_step(index): keystr1 = str(index[9]) keystr2 = str(index[13]) ser = Series(np.arange(20), index) SLC = IndexSlice for key in [keystr1, index[9]]: tm.assert_indexing_slices_equivalent(ser, SLC[key::-1], SLC[9::-1]) tm.assert_indexing_slices_equivalent(ser, SLC[:key:-1], SLC[:8:-1]) for key2 in [keystr2, index[13]]: tm.assert_indexing_slices_equivalent(ser, SLC[key2:key:-1], SLC[13:8:-1]) tm.assert_indexing_slices_equivalent(ser, SLC[key:key2:-1], SLC[0:0:-1])
def test_str_label_slicing_with_negative_step(self): SLC = pd.IndexSlice for idx in [ _mklbl("A", 20), np.arange(20) + 100, np.linspace(100, 150, 20) ]: idx = Index(idx) ser = Series(np.arange(20), index=idx) tm.assert_indexing_slices_equivalent(ser, SLC[idx[9]::-1], SLC[9::-1]) tm.assert_indexing_slices_equivalent(ser, SLC[:idx[9]:-1], SLC[:8:-1]) tm.assert_indexing_slices_equivalent(ser, SLC[idx[13]:idx[9]:-1], SLC[13:8:-1]) tm.assert_indexing_slices_equivalent(ser, SLC[idx[9]:idx[13]:-1], SLC[:0])
def test_multiindex_label_slicing_with_negative_step(self): ser = Series(np.arange(20), MultiIndex.from_product([list("abcde"), np.arange(4)])) SLC = pd.IndexSlice tm.assert_indexing_slices_equivalent(ser, SLC[::-1], SLC[::-1]) tm.assert_indexing_slices_equivalent(ser, SLC["d"::-1], SLC[15::-1]) tm.assert_indexing_slices_equivalent(ser, SLC[("d", )::-1], SLC[15::-1]) tm.assert_indexing_slices_equivalent(ser, SLC[:"d":-1], SLC[:11:-1]) tm.assert_indexing_slices_equivalent(ser, SLC[:("d", ):-1], SLC[:11:-1]) tm.assert_indexing_slices_equivalent(ser, SLC["d":"b":-1], SLC[15:3:-1]) tm.assert_indexing_slices_equivalent(ser, SLC[("d", ):"b":-1], SLC[15:3:-1]) tm.assert_indexing_slices_equivalent(ser, SLC["d":("b", ):-1], SLC[15:3:-1]) tm.assert_indexing_slices_equivalent(ser, SLC[("d", ):("b", ):-1], SLC[15:3:-1]) tm.assert_indexing_slices_equivalent(ser, SLC["b":"d":-1], SLC[:0]) tm.assert_indexing_slices_equivalent(ser, SLC[("c", 2)::-1], SLC[10::-1]) tm.assert_indexing_slices_equivalent(ser, SLC[:("c", 2):-1], SLC[:9:-1]) tm.assert_indexing_slices_equivalent(ser, SLC[("e", 0):("c", 2):-1], SLC[16:9:-1])