-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DEPR: Deprecate returning a DataFrame in SeriesApply.apply_standard #52123
DEPR: Deprecate returning a DataFrame in SeriesApply.apply_standard #52123
Conversation
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.
It's not clear to me what the output in this case will be after the deprecation. Can you give an example?
53d4a16
to
7aee834
Compare
This pattern should not be used with IF they use the same method after the change, they will get a >>> import pandas as pd
>>> ser = pd.Series(range(3))
>>> func = lambda x: pd.Series({"x": x, "x**2": x**2})
>>> ser.apply(func) # now
x x**2
0 1 1
1 2 4
2 3 9
>>> ser.apply(func) # after change
0 x 0
x**2 0
dtype: int64
1 x 1
x**2 1
dtype: int64
2 x 2
x**2 4
dtype: int64
dtype: object
>>> ser.apply(func)[0] # single element after change
x 0
x**2 0
dtype: int64 This pattern will be not useful generally after the change is implemented, so they should use better patterns, e.g. >>> func = lambda x: pd.DataFrame({"x": x, "x**2": x**2})
>>> ser.pipe(func) # now & after this deprecation, it's faster
x x**2
0 0 0
1 1 1
2 2 4
>>> pd.DataFrame({"x": ser, "x**2": ser**2}) # or this...
x x**2
0 0 0
1 1 1
2 2 4 Just find something better/faster than that old pattern... |
f3f2cd9
to
fe857a4
Compare
51b839d
to
d6cb073
Compare
I've addressed the comments by @rhshadrach. |
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 @topper-123 |
@topper-123 This tripped up a test we do on nightly builds in pandas-stubs, which we can fix, but I think the error message could be improved. If the recommendation is to use Also, the error message doesn't look right due to spacing: >>> import pandas as pd
>>> pd.__version__
'2.1.0.dev0+463.ge9e034badb'
>>> s = pd.Series([-10, 2, 2, 3.4, 10, 10])
>>> def makeseries(x: float) -> pd.Series:
... return pd.Series([x, 2 * x])
...
>>> s.apply(makeseries)
<stdin>:1: FutureWarning: Returning a DataFrame from Series.apply when the supplied functionreturns a Series is deprecated and will be removed in a future version.
0 1
0 -10.0 -20.0
1 2.0 4.0
2 2.0 4.0
3 3.4 6.8
4 10.0 20.0
5 10.0 20.0 Note the "functionreturns" misses a space. Let me know if I should create a separate issue for this. |
Hi @Dr-Irv. The ability to have series put into a A general pattern you could exchange the deprecated patterns with would be to do it like You're right about the error message, there's a missing space there. Tell me what you think about the above. |
I think you'll need to expand on this topic in the
This is a useful construct - you have a pd.DataFrame(s, columns=['s']).assign(x=lambda df: df.s, x2=lambda df: df.s ** 2).drop(columns=["s"]) There are clearly multiple alternatives, but with this deprecation, I think you might want to demonstrate those alternatives in the |
warnings.warn( | ||
"Returning a DataFrame from Series.apply when the supplied function" | ||
"returns a Series is deprecated and will be removed in a future " | ||
"version.", |
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.
This message should point users to a resource that is explaining what to do now
Agreed with @Dr-Irv This needs more explanation somewhere about what to do now |
There isa DeprecationWarning missing:
Looks like axis takes another path? |
…andard (pandas-dev#52123)" This reverts commit fe415f5
…andard (pandas-dev#55189) * Revert "DEPR: Deprecate returning a DataFrame in SeriesApply.apply_standard (pandas-dev#52123)" This reverts commit fe415f5 * Fix tests * Add whatsnew * Add whatsnew * Add test
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.