-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: new .agg for list-likes #43736
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
Closed
Closed
ENH: new .agg for list-likes #43736
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
3dfb779
ENH: new .agg for list-likes
rhshadrach 9ef1eb0
Refactor single arg computation, test fixup
rhshadrach 1974e07
Revert change to GroupBy.agg
rhshadrach af18184
Merge branch 'master' of https://github.com/pandas-dev/pandas into ne…
rhshadrach d7b6c7f
Rename option and methods
rhshadrach af002fc
Merge branch 'master' of https://github.com/pandas-dev/pandas into ne…
rhshadrach d412b4f
Merge fixups
rhshadrach 0cea15b
BUG/ERR: sparse array cmp methods mismatched len (#43863)
mzeitlin11 665b304
Add deprecation tag for passing a string for ewm(times=...) (#43873)
mroeschke 214ba4a
Make components of Suffixes Optional (#42544)
scravy 9d6da6d
BUG: Fix dtypes for read_json (#42819)
r-raymond 005598c
TST: dropping of nuisance columns for groupby ops #38815 (#43674)
horaceklai 7afb062
BUG: retain EA dtypes in DataFrame __pos__, __neg__ (#43883)
jbrockmendel 195f9cf
TST: Test Series' settitem with Interval and NaN (#43844)
ElDeveloper 6021c06
PERF: tighter cython declarations, faster __iter__ (#43872)
jbrockmendel aa0a1d6
PERF: read_csv with memory_map=True when file encoding is UTF-8 (#437…
michal-gh ef35a19
TYP: enable reportMissingImports (#43790)
twoertwein eefd0f0
Don't suppress exception chaining for optional dependencies (#43882)
takluyver d3f5a44
BUG: DataFrame arithmetic with subclass where constructor is not the …
jbrockmendel 1146215
REF: remove _get_attributes_dict (#43895)
jbrockmendel 58ff02d
Annotates `indexers/utils.py` functions that don't return anything wi…
sobolevn c9b0a6d
CI: Test Python 3.10 on MacOS and Windows too (#43772)
lithomas1 28c28c7
ENH: ExponentialMovingWindow.sum (#43871)
mroeschke f157d4d
TST: slow collection in test_algos.py (#43898)
mzeitlin11 cdc7b4a
ENH: implement ExtensionArray.__array_ufunc__ (#43899)
jbrockmendel 2688ca8
[ENH] introducing IntpHashMap and making unique_label_indices use int…
realead 5fe8d7d
ENH: implement Index.__array_ufunc__ (#43904)
jbrockmendel a49977c
TST/REF: share/split index tests (#43905)
jbrockmendel 4779171
TST/REF: misplaced Index.putmask tests (#43906)
jbrockmendel d4ae657
Add clarifications to the docs regarding `to_feather` (#43866)
jmakov bde9b11
TST/REF: collect/de-dup index tests (#43914)
jbrockmendel ecab3a2
BENCH: indexing_engines (#43916)
jbrockmendel adef17c
TST: avoid re-running tests 14 times (#43922)
jbrockmendel d5716c7
CLN: unnecessary warning-catching (#43919)
jbrockmendel 505ed3f
TST/REF: fixturize (#43918)
jbrockmendel 9ee956b
BUG: NumericIndex.insert (#43933)
jbrockmendel 1e370aa
TST: Skip leaky test on Python 3.10 (#43910)
lithomas1 acb7650
ENH: EA.tolist (#43920)
jbrockmendel e12643e
fixed rolling for a decreasing index, added a test for that (#43928)
rosagold 8a454e0
Merge branch 'master' of https://github.com/pandas-dev/pandas into ne…
rhshadrach 3bba371
Added docs
rhshadrach 4a69adf
Merge branch 'master' of https://github.com/pandas-dev/pandas into ne…
rhshadrach 7abdff9
Make quotes consistent
rhshadrach a72a5eb
Fixup docs
rhshadrach f8aa318
Merge branch 'master' of https://github.com/pandas-dev/pandas into ne…
rhshadrach afc27ba
Merge cleanup
rhshadrach f42eb00
Merge branch 'new_udfs_list_agg' of https://github.com/rhshadrach/pan…
rhshadrach 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
.. _future_udf_behavior: | ||
|
||
:orphan: | ||
|
||
{{ header }} | ||
|
||
******************* | ||
Future UDF Behavior | ||
******************* | ||
|
||
pandas is experimenting with improving the behavior of methods that take a | ||
user-defined function (UDF). These methods include ``.apply``, ``.agg``, ``.transform``, | ||
and ``.filter``. The goal is to make these methods behave in a more predictable | ||
and consistent manner, reducing the complexity of their implementation, and improving | ||
performance where possible. This page details the differences between the old and | ||
new behaviors, as well as providing some context behind each change that is being made. | ||
|
||
There are a great number of changes that are planned. In order to transition in a | ||
reasonable manner for users, all changes are behind an experimental "future_udf_behavior" | ||
option. This is currently experimental and subject to breaking changes without notice. | ||
Users can opt into the new behavior and provide feedback. Once the improvements have | ||
been made, this option will be declared no longer experimental. pandas will then raise | ||
a ``FutureWarning`` that the default value of this option will be set to ``True`` in | ||
a future version. Once the default is ``True``, users can still override it to ``False``. | ||
After a sufficient amount of time, pandas will remove this option altogether and only | ||
the future behavior will remain. | ||
|
||
``DataFrame.agg`` with list-likes | ||
--------------------------------- | ||
|
||
Previously, using ``DataFrame.agg`` with a list-like argument would transpose the result when | ||
compared with just providing a single aggregation function. | ||
|
||
.. ipython:: python | ||
|
||
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6], "c": [7, 8, 9]}) | ||
|
||
df.agg("sum") | ||
df.agg(["sum"]) | ||
|
||
This transpose no longer occurs, making the result more consistent. | ||
|
||
.. ipython:: python | ||
|
||
with pd.option_context("future_udf_behavior", True): | ||
result = df.agg(["sum"]) | ||
result | ||
|
||
with pd.option_context("future_udf_behavior", True): | ||
result = df.agg(["sum", "mean"]) | ||
result | ||
|
||
``DataFrame.groupby(...).agg`` with list-likes | ||
---------------------------------------------- | ||
|
||
Previously, using ``DataFrame.groupby(...).agg`` with a list-like argument would put the | ||
columns as the first level of the resulting hierarchical columns. The result is | ||
that the columns for each aggregation function are separated, inconsistent with the result | ||
for a single aggregator. | ||
|
||
.. ipython:: python | ||
|
||
df.groupby("a").agg("sum") | ||
df.groupby("a").agg(["sum", "min"]) | ||
|
||
Now the levels are swapped, so that the columns for each aggregation are together. | ||
|
||
.. ipython:: python | ||
|
||
with pd.option_context("future_udf_behavior", True): | ||
result = df.groupby("a").agg(["sum", "min"]) | ||
result |
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
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
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
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
Oops, something went wrong.
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.
same request from the other PR re naming; "future" won't be very helpful for a reader a year from now
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.
The intention is to have "future_" methods alongside the current methods; all with the same prefix so they are easy to identify. Any such method is behind the option "future_udf_behavior" meaning they will only be called when set to True. Assuming we do end up going forward with this new (experimental) behavior, once it is in a good place we deprecate the option and then remove the option.
A year from now, we will still have the option "future_udf_behavior", and in my opinion, the "future_" prefix is meaningful and helpful - namely in its connection to this option. It is also the (intended) future behavior of the methods. When the option is removed, the "old" methods are removed and the "future_" methods are renamed by removing the prefix (none are public).
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.
you've clearly given this more thought than i have so im going to stop complaining about this, will instead grumble to myself
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.
The name is still up for improvements and suggestions are most welcome, but wanted to explain why I felt "future" was appropriate.