-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
TST: added test for groupby when calling first, last, nth (GH29645) #43358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pandas/tests/groupby/test_groupby.py
Outdated
|
||
|
||
@pytest.mark.parametrize("method", ["first", "last", "nth"]) | ||
def test_groupby_last_first_nth_with_none(method): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please define expected without applying a method and then parametrize over None and nan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand what you mean: the issue states that None
and np.nan
should lead to the same result when I groupby
and apply a method. If I don't apply a method, then what's the point of the test? My reasoning was: I have two Series
with None
and np.nan
and I have to test that grouping with a method gives the same output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would want to test the expected output explicitly. If both yield the same, the result may be incorrect nevertheless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I get what you mean
pandas/tests/groupby/test_groupby.py
Outdated
expected = Series([True]) | ||
data = ( | ||
Series([nans, "x", nans, "y", nans], index=[0, 0, 0, 0, 0]) | ||
.isna() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
pandas/tests/groupby/test_groupby.py
Outdated
@@ -2419,3 +2419,20 @@ 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"]) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
thanks @lorenzophys |
Provided test for
groupby
when calllingfirst
,last
,nth
on aSeries
withNone
ornp.nan
.Tests and linter pass locally.