-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: idxmin & idxmax axis = 1 str reducer for transform #50329
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9751f6d
Fix axis=1 behaviour for str reducer idxmin
iofall 9150581
Add DataFrame._get_axis_number
iofall 78c0977
Ignore axis argument for groupby idxmin
iofall 63bcc5f
Fix doctest
iofall b2e6567
Fix idxmax axis=1 failure
iofall 4ac6d16
Fix merge conflict for whatsnew
iofall 564c6fc
Modify whatsnew entry
iofall 41bcc9a
Default axis to None
iofall e615991
Fix merge conflict whatsnew
iofall 62f2a60
Change axis typehint for idxmax and idxmin
iofall 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 hidden or 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 |
---|---|---|
|
@@ -1879,16 +1879,82 @@ def func(df): | |
) | ||
return result | ||
|
||
@doc( | ||
_shared_docs["idxmin"], | ||
numeric_only_default="False", | ||
) | ||
def idxmin( | ||
self, | ||
axis: Axis = 0, | ||
skipna: bool = True, | ||
numeric_only: bool = False, | ||
) -> DataFrame: | ||
""" | ||
Return index of first occurrence of minimum over requested axis. | ||
|
||
NA/null values are excluded. | ||
|
||
Parameters | ||
---------- | ||
axis : {{0 or 'index', 1 or 'columns'}}, default 0 | ||
The axis to use. 0 or 'index' for row-wise, 1 or 'columns' for column-wise. | ||
The axis argument is ignored, instead we use the grouper's axis. | ||
|
||
.. versionchanged:: 1.5.3 | ||
|
||
skipna : bool, default True | ||
Exclude NA/null values. If an entire row/column is NA, the result | ||
will be NA. | ||
numeric_only : bool, default False | ||
Include only `float`, `int` or `boolean` data. | ||
|
||
.. versionadded:: 1.5.0 | ||
|
||
Returns | ||
------- | ||
Series | ||
Indexes of minima along the specified axis. | ||
|
||
Raises | ||
------ | ||
ValueError | ||
* If the row/column is empty | ||
|
||
See Also | ||
-------- | ||
Series.idxmin : Return index of the minimum element. | ||
|
||
Notes | ||
----- | ||
This method is the DataFrame version of ``ndarray.argmin``. | ||
|
||
Examples | ||
-------- | ||
Consider a dataset containing food consumption in Argentina. | ||
|
||
>>> df = pd.DataFrame({'consumption': [10.51, 103.11, 55.48], | ||
... 'co2_emissions': [37.2, 19.66, 1712]}, | ||
... index=['Pork', 'Wheat Products', 'Beef']) | ||
|
||
>>> df | ||
consumption co2_emissions | ||
Pork 10.51 37.20 | ||
Wheat Products 103.11 19.66 | ||
Beef 55.48 1712.00 | ||
|
||
By default, it returns the index for the minimum value in each column. | ||
|
||
>>> df.idxmin() | ||
consumption Pork | ||
co2_emissions Wheat Products | ||
dtype: object | ||
|
||
To return the index for the minimum value in each row, use ``axis="columns"``. | ||
|
||
>>> df.idxmin(axis="columns") | ||
Pork consumption | ||
Wheat Products co2_emissions | ||
Beef consumption | ||
dtype: object | ||
""" | ||
|
||
axis = self.axis | ||
axis = DataFrame._get_axis_number(axis) | ||
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. L1958 here is now unnecessary, as self.axis is always 0 or 1. 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. Yes, makes sense |
||
|
||
def func(df): | ||
|
This file contains hidden or 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
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.
2.0.0 here; in generally only regression fixes make it to patch versions.