From 3fc8f65ef810acd742ef815242c7beb72c50587f Mon Sep 17 00:00:00 2001 From: smithto1 Date: Sat, 1 Aug 2020 13:53:24 +0100 Subject: [PATCH 1/4] new test --- pandas/tests/groupby/test_apply.py | 32 +++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 5a1268bfb03db..6792b87ee8ad7 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, date from io import StringIO import numpy as np @@ -1014,3 +1014,33 @@ def test_apply_with_timezones_aware(): result2 = df2.groupby("x", group_keys=False).apply(lambda df: df[["x", "y"]].copy()) tm.assert_frame_equal(result1, result2) + + +def test_apply_with_date_in_multiindex_does_not_convert_to_timestamp(): + # GH 29617 + + df = pd.DataFrame( + { + "A": ["a", "a", "a", "b"], + "B": [ + date(2020, 1, 10), + date(2020, 1, 10), + date(2020, 2, 10), + date(2020, 2, 10), + ], + "C": [1, 2, 3, 4], + }, + index=pd.Index([100, 101, 102, 103], name="idx"), + ) + + grp = df.groupby(["A", "B"]) + result = grp.apply(lambda x: x.head(1)) + + expected = df.iloc[[0, 2, 3]] + expected = expected.reset_index() + expected.index = pd.MultiIndex.from_frame(expected[["A", "B", "idx"]]) + expected = expected.drop(columns="idx") + + tm.assert_frame_equal(result, expected) + for val in result.index.levels[1]: + assert type(val) is date From 5d5fcd984698aa0df2f1dc38c3990c436b09e8b9 Mon Sep 17 00:00:00 2001 From: smithto1 Date: Sat, 1 Aug 2020 16:40:14 +0100 Subject: [PATCH 2/4] linting --- pandas/tests/groupby/test_apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 6792b87ee8ad7..525a6fe2637c3 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -1,4 +1,4 @@ -from datetime import datetime, date +from datetime import date, datetime from io import StringIO import numpy as np From 3c769451beb47c3f79736e242e21422a9416e270 Mon Sep 17 00:00:00 2001 From: smithto1 Date: Sat, 1 Aug 2020 23:56:29 +0100 Subject: [PATCH 3/4] amend comment to restart tests --- pandas/tests/groupby/test_apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index 525a6fe2637c3..e31721a40d720 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -1017,7 +1017,7 @@ def test_apply_with_timezones_aware(): def test_apply_with_date_in_multiindex_does_not_convert_to_timestamp(): - # GH 29617 + # GH #29617 df = pd.DataFrame( { From 5636d494cf4bfc58a2d5d321fd8623f554692928 Mon Sep 17 00:00:00 2001 From: smithto1 Date: Sun, 2 Aug 2020 19:43:20 +0100 Subject: [PATCH 4/4] amend comment to start tests --- pandas/tests/groupby/test_apply.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/groupby/test_apply.py b/pandas/tests/groupby/test_apply.py index e31721a40d720..525a6fe2637c3 100644 --- a/pandas/tests/groupby/test_apply.py +++ b/pandas/tests/groupby/test_apply.py @@ -1017,7 +1017,7 @@ def test_apply_with_timezones_aware(): def test_apply_with_date_in_multiindex_does_not_convert_to_timestamp(): - # GH #29617 + # GH 29617 df = pd.DataFrame( {