Skip to content

Commit 5a3e722

Browse files
committed
changed comments
1 parent ca40652 commit 5a3e722

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

pandas/tests/groupby/test_grouping.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,17 +1182,26 @@ def test_grouping_by_key_is_in_axis():
11821182
tm.assert_frame_equal(result, expected)
11831183

11841184

1185-
def test_groupby_any_with_timedelta(self):
1186-
# Create a DataFrame with Timedelta and NaT values
1187-
df = DataFrame({
1185+
def test_groupby_any_with_timedelta():
1186+
# Create a DataFrame with Timedelta and NaT values
1187+
df = DataFrame(
1188+
{
11881189
"A": ["foo", "foo", "bar", "bar"],
1189-
"B": [pd.Timedelta(1, unit='D'), pd.NaT, pd.Timedelta(2, unit='D'), pd.NaT]
1190-
})
1190+
"B": [pd.Timedelta(1, unit="D"), pd.NaT, pd.Timedelta(2, unit="D"), pd.NaT],
1191+
}
1192+
)
11911193

1192-
# Group by column A and check if any Timedelta exists (i.e., non-NaT)
1193-
result = df.groupby("A")["B"].any()
1194+
# Group by column A with sorting enabled and check if any Timedelta exists
1195+
result = df.groupby("A", sort=True)["B"].any()
11941196

1195-
# Expected result: groups with only NaT should return False, others should return True
1196-
expected = Series([True, False], index=["foo", "bar"], name="B")
1197+
# Corrected expected result: groups with only NaT should return False, else True
1198+
expected = Series([True, True], index=["foo", "bar"], name="B")
11971199

1198-
tm.assert_series_equal(result, expected)
1200+
# Set the expected index name to match the result
1201+
expected.index.name = "A"
1202+
1203+
# Sort the expected result to match the order of result
1204+
expected = expected.sort_index()
1205+
1206+
# Assert that the result matches the expected output
1207+
tm.assert_series_equal(result, expected)

0 commit comments

Comments
 (0)