Skip to content

Commit 41e0f07

Browse files
committed
TST: add test for last method on dataframe grouped by on boolean column (pandas-dev#46409)
1 parent 0a8b45f commit 41e0f07

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

pandas/tests/frame/methods/test_dtypes.py

+18
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ def test_dtypes_are_correct_after_column_slice(self):
7979
Series({"a": np.float_, "b": np.float_, "c": np.float_}),
8080
)
8181

82+
def test_dtypes_are_correct_after_groupby_last(self):
83+
# GH46409
84+
df1 = DataFrame(
85+
{"id": [1, 2, 3, 4], "test": [True, pd.NA, pd.NA, False]}
86+
).convert_dtypes()
87+
88+
df2 = DataFrame(
89+
{"id": [1, 2, 3, 4], "test": [True, pd.NA, True, False]}
90+
).convert_dtypes()
91+
92+
grouped1 = df1.groupby("id")
93+
last1 = grouped1.last()
94+
grouped2 = df2.groupby("id")
95+
last2 = grouped2.last()
96+
97+
assert last1.test.dtype == pd.BooleanDtype()
98+
assert last2.test.dtype == pd.BooleanDtype()
99+
82100
def test_dtypes_gh8722(self, float_string_frame):
83101
float_string_frame["bool"] = float_string_frame["A"] > 0
84102
result = float_string_frame.dtypes

0 commit comments

Comments
 (0)