11import numpy as np
22import pytest
33
4- from pandas import Series , timedelta_range
4+ from pandas import IndexSlice , Series , timedelta_range
55import pandas ._testing as tm
66
77
@@ -44,40 +44,4 @@ def test_partial_slice_high_reso(self):
4444 tm .assert_series_equal (result , expected )
4545
4646 result = s ["1 days, 10:11:12.001001" ]
47- assert result == s .iloc [1001 ]
48-
49- def test_slice_with_negative_step (self ):
50- ts = Series (np .arange (20 ),
51- timedelta_range ('0ns' , periods = 20 , freq = 'H' ))
52- SLC = pd .IndexSlice
53-
54- def assert_slices_equivalent (l_slc , i_slc ):
55- assert_series_equal (ts [l_slc ], ts .iloc [i_slc ])
56- assert_series_equal (ts .loc [l_slc ], ts .iloc [i_slc ])
57- assert_series_equal (ts .loc [l_slc ], ts .iloc [i_slc ])
58-
59- assert_slices_equivalent (SLC [Timedelta (hours = 7 )::- 1 ], SLC [7 ::- 1 ])
60- assert_slices_equivalent (SLC ['7 hours' ::- 1 ], SLC [7 ::- 1 ])
61-
62- assert_slices_equivalent (SLC [:Timedelta (hours = 7 ):- 1 ], SLC [:6 :- 1 ])
63- assert_slices_equivalent (SLC [:'7 hours' :- 1 ], SLC [:6 :- 1 ])
64-
65- assert_slices_equivalent (SLC ['15 hours' :'7 hours' :- 1 ], SLC [15 :6 :- 1 ])
66- assert_slices_equivalent (SLC [Timedelta (hours = 15 ):Timedelta (hours = 7 ):-
67- 1 ], SLC [15 :6 :- 1 ])
68- assert_slices_equivalent (SLC ['15 hours' :Timedelta (hours = 7 ):- 1 ],
69- SLC [15 :6 :- 1 ])
70- assert_slices_equivalent (SLC [Timedelta (hours = 15 ):'7 hours' :- 1 ],
71- SLC [15 :6 :- 1 ])
72-
73- assert_slices_equivalent (SLC ['7 hours' :'15 hours' :- 1 ], SLC [:0 ])
74-
75- def test_slice_with_zero_step_raises (self ):
76- ts = Series (np .arange (20 ),
77- timedelta_range ('0ns' , periods = 20 , freq = 'H' ))
78- with pytest .raises (ValueError , match = 'slice step cannot be zero' ):
79- ts [::0 ]
80- with pytest .raises (ValueError , match = 'slice step cannot be zero' ):
81- ts .loc [::0 ]
82- with pytest .raises (ValueError , match = 'slice step cannot be zero' ):
83- ts .loc [::0 ]
47+ assert result == s .iloc [1001 ]
0 commit comments