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