@@ -640,26 +640,22 @@ def test_at_time_raises(self):
640
640
with pytest .raises (TypeError ): # index is not a DatetimeIndex
641
641
df .at_time ('00:00' )
642
642
643
- @pytest .mark .parametrize ('time_axis' , [
644
- (False , False ), (True , False ), (False , True ), (True , True )])
645
- def test_at_time_axis (self , time_axis ):
643
+ @pytest .mark .parametrize ('axis' , ['index' , 'columns' ])
644
+ def test_at_time_axis (self , axis ):
646
645
# issue 8839
647
646
rng = date_range ('1/1/2000' , '1/5/2000' , freq = '5min' )
648
647
ts = DataFrame (np .random .randn (len (rng ), len (rng )))
648
+ ts .index , ts .columns = rng , rng
649
649
650
650
indices = rng [(rng .hour == 9 ) & (rng .minute == 30 ) & (rng .second == 0 )]
651
651
652
- if time_axis [0 ]:
653
- ts .index = rng
654
- expected = ts .loc [indices ]
655
- result = ts .at_time ('9:30' , axis = 0 )
656
- assert_frame_equal (result , expected )
657
-
658
- if time_axis [1 ]:
659
- ts .columns = rng
652
+ if axis == 'index' :
653
+ expected = ts .loc [indices , :]
654
+ elif axis == 'columns' :
660
655
expected = ts .loc [:, indices ]
661
- result = ts .at_time ('9:30' , axis = 1 )
662
- assert_frame_equal (result , expected )
656
+
657
+ result = ts .at_time ('9:30' , axis = axis )
658
+ assert_frame_equal (result , expected )
663
659
664
660
def test_between_time (self ):
665
661
rng = date_range ('1/1/2000' , '1/5/2000' , freq = '5min' )
@@ -727,38 +723,42 @@ def test_between_time_raises(self):
727
723
with pytest .raises (TypeError ): # index is not a DatetimeIndex
728
724
df .between_time (start_time = '00:00' , end_time = '12:00' )
729
725
730
- @pytest .mark .parametrize ('time_axis ' , [
731
- (False , False ), ( True , False ) , (False , True ), ( True , True )])
732
- def test_between_time_axis (self , time_axis ):
726
+ @pytest .mark .parametrize ('axis ' , [
727
+ (), 'index' , 'columns' , ('index' , 'columns' )])
728
+ def test_between_time_axis (self , axis ):
733
729
# issue 8839
734
730
rng = date_range ('1/1/2000' , periods = 100 , freq = '10min' )
735
- blank = np .arange ( 0 , len (rng ))
731
+ ts = DataFrame ( np .random . randn ( len ( rng ) , len (rng ) ))
736
732
stime , etime = ('08:00:00' , '09:00:00' )
737
- rand_data = np .random .randn (len (rng ), len (rng ))
738
733
exp_len = 7
739
734
740
- if time_axis [0 ]:
741
- index = rng
742
- else :
743
- index = blank
744
- if time_axis [1 ]:
745
- col = rng
746
- else :
747
- col = blank
748
-
749
- ts = DataFrame (rand_data , index = index , columns = col )
750
-
751
- if time_axis [0 ]:
735
+ if 'index' in axis :
736
+ ts .index = rng
752
737
assert len (ts .between_time (stime , etime )) == exp_len
753
738
assert len (ts .between_time (stime , etime , axis = 0 )) == exp_len
754
- else :
755
- pytest .raises (TypeError , ts .between_time , stime , etime )
756
- pytest .raises (TypeError , ts .between_time , stime , etime , axis = 0 )
757
739
758
- if time_axis [1 ]:
740
+ if 'columns' in axis :
741
+ ts .columns = rng
759
742
selected = ts .between_time (stime , etime , axis = 1 ).columns
760
743
assert len (selected ) == exp_len
761
- else :
744
+
745
+ @pytest .mark .parametrize ('axis' , [
746
+ (), 'index' , 'columns' , ('index' , 'columns' )])
747
+ def test_between_time_axis_raises (self , axis ):
748
+ # issue 8839
749
+ rng = date_range ('1/1/2000' , periods = 100 , freq = '10min' )
750
+ mask = np .arange (0 , len (rng ))
751
+ rand_data = np .random .randn (len (rng ), len (rng ))
752
+ ts = DataFrame (rand_data , index = rng , columns = rng )
753
+ stime , etime = ('08:00:00' , '09:00:00' )
754
+
755
+ if 'index' not in axis :
756
+ ts .index = mask
757
+ pytest .raises (TypeError , ts .between_time , stime , etime )
758
+ pytest .raises (TypeError , ts .between_time , stime , etime , axis = 0 )
759
+
760
+ if 'columns' not in axis :
761
+ ts .columns = mask
762
762
pytest .raises (TypeError , ts .between_time , stime , etime , axis = 1 )
763
763
764
764
def test_operation_on_NaT (self ):
0 commit comments