Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -2419,3 +2419,22 @@ def test_rolling_wrong_param_min_period():
result_error_msg = r"__init__\(\) got an unexpected keyword argument 'min_period'"
with pytest.raises(TypeError, match=result_error_msg):
test_df.groupby("name")["val"].rolling(window=2, min_period=1).sum()


@pytest.mark.parametrize("method", ["first", "last", "nth"])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move to test_nth.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing

@pytest.mark.parametrize("nans", [None, np.nan])
def test_groupby_last_first_nth_with_none(method, nans):
# GH29645
expected = Series([True])
data = (
Series([nans, "x", nans, "y", nans], index=[0, 0, 0, 0, 0])
.isna()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think isna is necessary.

Does parametrization over all missing values work? pd.NA, NaT etc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean something like @pytest.mark.parametrize("nans", [None, np.nan, pd.NA, pd.NaT]) without isna then no, all tests fail. They all pass if isna is there

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you check the same as in #29645 (comment)? We do not want to check for True False rather than for "y".

We have a missing value fixture, but yes I meant like this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable, I misunderstood

.groupby(level=0)
)

if method == "nth":
result = getattr(data, method)(2)
else:
result = getattr(data, method)()

tm.assert_series_equal(result, expected)