File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -543,6 +543,33 @@ def predictions(tool):
543
543
tm .assert_series_equal (expected , result )
544
544
545
545
546
+ def test_apply_aggregating_timedelta_and_datetime ():
547
+ # Regression test for GH 15562
548
+ # The following groupby caused ValueErrors and IndexErrors pre 0.20.0
549
+
550
+ df = pd .DataFrame (
551
+ {
552
+ "clientid" : ["A" , "B" , "C" ],
553
+ "datetime" : [np .datetime64 ("2017-02-01 00:00:00" )] * 3 ,
554
+ }
555
+ )
556
+ df ["time_delta_zero" ] = df .datetime - df .datetime
557
+ result = df .groupby ("clientid" ).apply (
558
+ lambda ddf : pd .Series (
559
+ dict (clientid_age = ddf .time_delta_zero .min (), date = ddf .datetime .min ())
560
+ )
561
+ )
562
+ expected = pd .DataFrame (
563
+ {
564
+ "clientid" : ["A" , "B" , "C" ],
565
+ "clientid_age" : [np .timedelta64 (0 , "D" )] * 3 ,
566
+ "date" : [np .datetime64 ("2017-02-01 00:00:00" )] * 3 ,
567
+ }
568
+ ).set_index ("clientid" )
569
+
570
+ tm .assert_frame_equal (result , expected )
571
+
572
+
546
573
def test_time_field_bug ():
547
574
# Test a fix for the following error related to GH issue 11324 When
548
575
# non-key fields in a group-by dataframe contained time-based fields
You can’t perform that action at this time.
0 commit comments