@@ -1183,25 +1183,14 @@ def test_grouping_by_key_is_in_axis():
1183
1183
1184
1184
1185
1185
def test_groupby_any_with_timedelta ():
1186
- # Create a DataFrame with Timedelta and NaT values
1187
- df = DataFrame (
1188
- {
1189
- "A" : ["foo" , "foo" , "bar" , "bar" ],
1190
- "B" : [pd .Timedelta (1 , unit = "D" ), pd .NaT , pd .Timedelta (2 , unit = "D" ), pd .NaT ],
1191
- }
1192
- )
1193
-
1194
- # Group by column A with sorting enabled and check if any Timedelta exists
1195
- result = df .groupby ("A" , sort = True )["B" ].any ()
1196
-
1197
- # Corrected expected result: groups with only NaT should return False, else True
1198
- expected = Series ([True , True ], index = ["foo" , "bar" ], name = "B" )
1186
+ # Create a DataFrame with a single column containing a Timedelta and NaT
1187
+ df = DataFrame ({"value" : [pd .Timedelta (1 ), pd .NaT ]})
1199
1188
1200
- # Set the expected index name to match the result
1201
- expected . index . name = "A"
1189
+ # Perform groupby().any() operation
1190
+ result = df . groupby ( np . array ([ 0 , 1 ]))[ "value" ]. any ()
1202
1191
1203
- # Sort the expected result to match the order of result
1204
- expected = expected . sort_index ( )
1192
+ # Expected result: group with NaT should return False
1193
+ expected = Series ({ 0 : True , 1 : False }, name = "value" )
1205
1194
1206
- # Assert that the result matches the expected output
1195
+ # Check if the result matches the expected output
1207
1196
tm .assert_series_equal (result , expected )
0 commit comments