@@ -539,7 +539,59 @@ def test_first_last_valid(self):
539539 assert frame .first_valid_index ().freq == frame .index .freq
540540 assert frame .last_valid_index ().freq == frame .index .freq
541541
542- def test_at_time_frame (self ):
542+ def test_first_subset (self ):
543+ ts = tm .makeTimeDataFrame (freq = '12h' )
544+ result = ts .first ('10d' )
545+ assert len (result ) == 20
546+
547+ ts = tm .makeTimeDataFrame (freq = 'D' )
548+ result = ts .first ('10d' )
549+ assert len (result ) == 10
550+
551+ result = ts .first ('3M' )
552+ expected = ts [:'3/31/2000' ]
553+ assert_frame_equal (result , expected )
554+
555+ result = ts .first ('21D' )
556+ expected = ts [:21 ]
557+ assert_frame_equal (result , expected )
558+
559+ result = ts [:0 ].first ('3M' )
560+ assert_frame_equal (result , ts [:0 ])
561+
562+ def test_first_raises (self ):
563+ # GH20725
564+ df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
565+ with pytest .raises (TypeError ): # index is not a DatetimeIndex
566+ df .first ('1D' )
567+
568+ def test_last_subset (self ):
569+ ts = tm .makeTimeDataFrame (freq = '12h' )
570+ result = ts .last ('10d' )
571+ assert len (result ) == 20
572+
573+ ts = ts = tm .makeTimeDataFrame (freq = 'D' )
574+ result = ts .last ('10d' )
575+ assert len (result ) == 10
576+
577+ result = ts .last ('21D' )
578+ expected = ts ['2000-01-10' :]
579+ assert_frame_equal (result , expected )
580+
581+ result = ts .last ('21D' )
582+ expected = ts [- 21 :]
583+ assert_frame_equal (result , expected )
584+
585+ result = ts [:0 ].last ('3M' )
586+ assert_frame_equal (result , ts [:0 ])
587+
588+ def test_last_raises (self ):
589+ # GH20725
590+ df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
591+ with pytest .raises (TypeError ): # index is not a DatetimeIndex
592+ df .last ('1D' )
593+
594+ def test_at_time (self ):
543595 rng = date_range ('1/1/2000' , '1/5/2000' , freq = '5min' )
544596 ts = DataFrame (np .random .randn (len (rng ), 2 ), index = rng )
545597 rs = ts .at_time (rng [1 ])
@@ -569,7 +621,13 @@ def test_at_time_frame(self):
569621 rs = ts .at_time ('16:00' )
570622 assert len (rs ) == 0
571623
572- def test_between_time_frame (self ):
624+ def test_at_time_raises (self ):
625+ # GH20725
626+ df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
627+ with pytest .raises (TypeError ): # index is not a DatetimeIndex
628+ df .at_time ('00:00' )
629+
630+ def test_between_time (self ):
573631 rng = date_range ('1/1/2000' , '1/5/2000' , freq = '5min' )
574632 ts = DataFrame (np .random .randn (len (rng ), 2 ), index = rng )
575633 stime = time (0 , 0 )
@@ -629,6 +687,12 @@ def test_between_time_frame(self):
629687 else :
630688 assert (t < etime ) or (t >= stime )
631689
690+ def test_between_time_raises (self ):
691+ # GH20725
692+ df = pd .DataFrame ([[1 , 2 , 3 ], [4 , 5 , 6 ]])
693+ with pytest .raises (TypeError ): # index is not a DatetimeIndex
694+ df .between_time (start_time = '00:00' , end_time = '12:00' )
695+
632696 def test_operation_on_NaT (self ):
633697 # Both NaT and Timestamp are in DataFrame.
634698 df = pd .DataFrame ({'foo' : [pd .NaT , pd .NaT ,
0 commit comments