-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
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
ENH: Groupby.transform support string input with engine=numba #53579
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
45a2721
ENH: Groupby.transform support string input with engine=numba
lithomas1 ce9f4fb
Merge branch 'main' of https://github.com/pandas-dev/pandas into numb…
lithomas1 ec1da0c
remove xfail
lithomas1 0c40b05
Merge branch 'main' into numba-transform-str
lithomas1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,20 +130,25 @@ def func_1(values, index): | |
tm.assert_frame_equal(expected, result) | ||
|
||
|
||
# TODO: Test more than just reductions (e.g. actually test transformations once we have | ||
@td.skip_if_no("numba") | ||
@pytest.mark.parametrize( | ||
"agg_func", [["min", "max"], "min", {"B": ["min", "max"], "C": "sum"}] | ||
) | ||
def test_multifunc_notimplimented(agg_func): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to change the test since multifuncs (list/dicts of funcs) aren't supported anyways in transform for the cython engine as well. |
||
def test_string_cython_vs_numba(agg_func, numba_supported_reductions): | ||
agg_func, kwargs = numba_supported_reductions | ||
data = DataFrame( | ||
{0: ["a", "a", "b", "b", "a"], 1: [1.0, 2.0, 3.0, 4.0, 5.0]}, columns=[0, 1] | ||
) | ||
grouped = data.groupby(0) | ||
with pytest.raises(NotImplementedError, match="Numba engine can"): | ||
grouped.transform(agg_func, engine="numba") | ||
|
||
with pytest.raises(NotImplementedError, match="Numba engine can"): | ||
grouped[1].transform(agg_func, engine="numba") | ||
result = grouped.transform(agg_func, engine="numba", **kwargs) | ||
expected = grouped.transform(agg_func, engine="cython", **kwargs) | ||
tm.assert_frame_equal(result, expected) | ||
|
||
result = grouped[1].transform(agg_func, engine="numba", **kwargs) | ||
expected = grouped[1].transform(agg_func, engine="cython", **kwargs) | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@td.skip_if_no("numba") | ||
|
@@ -232,9 +237,6 @@ def numba_func(values, index): | |
|
||
|
||
@td.skip_if_no("numba") | ||
@pytest.mark.xfail( | ||
reason="Groupby transform doesn't support strings as function inputs yet with numba" | ||
) | ||
def test_multilabel_numba_vs_cython(numba_supported_reductions): | ||
reduction, kwargs = numba_supported_reductions | ||
df = DataFrame( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since there are no transformation kernels(e.g. cumsum, shift etc.) for numba yet, this is untested.
Should be OK, though, since this didn't work before anyways.
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.
Curious, what type of error do we get when we pass
engine="cython", engine_kwargs={"nogil": True}
?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.
IIRC, it gives something like
Groupby.method() got an unexpected argument engine