Skip to content

Commit b233e12

Browse files
committed
changed test
1 parent 2cb1ef2 commit b233e12

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

pandas/tests/groupby/test_grouping.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,25 +1183,14 @@ def test_grouping_by_key_is_in_axis():
11831183

11841184

11851185
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]})
11991188

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()
12021191

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")
12051194

1206-
# Assert that the result matches the expected output
1195+
# Check if the result matches the expected output
12071196
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)