From 2a5b9e7f91d2381ad4df85a838b90c80d197b4ce Mon Sep 17 00:00:00 2001 From: Shashwat Sharma Date: Sat, 2 Oct 2021 12:38:25 +0530 Subject: [PATCH 1/2] TST: added test for cut when labels are tuples of Timestamps (#40661) --- pandas/tests/reshape/test_cut.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandas/tests/reshape/test_cut.py b/pandas/tests/reshape/test_cut.py index c221a3a18911e..1387276026186 100644 --- a/pandas/tests/reshape/test_cut.py +++ b/pandas/tests/reshape/test_cut.py @@ -725,3 +725,14 @@ def test_cut_with_nonexact_categorical_indices(): ) tm.assert_frame_equal(expected, result) + + +def test_cut_with_timestamp_tuple_labels(): + # GH 40661 + data = [2, 4, 6] + bins = [1, 3, 5, 7] + labels = [(Timestamp(10),), (Timestamp(20),), (Timestamp(30),)] + result = cut(data, bins=bins, labels=labels) + + expected = Categorical.from_codes([0, 1, 2], labels, ordered=True) + tm.assert_categorical_equal(result, expected) From fc7bfb3751d750a4811de47ed0677d1d0281d5c7 Mon Sep 17 00:00:00 2001 From: Shashwat Sharma Date: Sun, 3 Oct 2021 13:04:20 +0530 Subject: [PATCH 2/2] pass data and bins directly to cut instead of as variables --- pandas/tests/reshape/test_cut.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/tests/reshape/test_cut.py b/pandas/tests/reshape/test_cut.py index 1387276026186..1425686f027e4 100644 --- a/pandas/tests/reshape/test_cut.py +++ b/pandas/tests/reshape/test_cut.py @@ -729,10 +729,8 @@ def test_cut_with_nonexact_categorical_indices(): def test_cut_with_timestamp_tuple_labels(): # GH 40661 - data = [2, 4, 6] - bins = [1, 3, 5, 7] labels = [(Timestamp(10),), (Timestamp(20),), (Timestamp(30),)] - result = cut(data, bins=bins, labels=labels) + result = cut([2, 4, 6], bins=[1, 3, 5, 7], labels=labels) expected = Categorical.from_codes([0, 1, 2], labels, ordered=True) tm.assert_categorical_equal(result, expected)