Skip to content

DOC: Updated convert_dtype of Series.apply #39941

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 8 commits into from
Apr 25, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4056,7 +4056,9 @@ def apply(
Python function or NumPy ufunc to apply.
convert_dtype : bool, default True
Try to find better dtype for elementwise function results. If
False, leave as dtype=object.
False, leave as dtype=object. For the dtypes Categorical,
Sparse, Interval, Period, DatetimeArray and TimedeltaArray
the original dtype is kept.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sukriti1 - how did you find this list of types? Was it from the code, or are they documented elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MarcoGorelli - I found this list of type from this comment :
#39580 (comment)

Copy link
Member

@MarcoGorelli MarcoGorelli Feb 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks!

OK, so instead of listing the dtypes here (which could expand in the future) maybe it's better to just say something like

note that conversion doesn't happen for extension array dtypes which have a map method (e.g. Categorical)

cc @attack68

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarcoGorelli Changes made!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreeing with @MarcoGorelli's second thought here, I do like the original wording better. Do we have tests for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can also add something to the effect that the list is not necessarily exhaustive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, "For some dtypes, such as Categorical,
Sparse, Interval, Period, DatetimeArray, and TimedeltaArray,
the original dtype is kept."?

args : tuple
Positional arguments passed to func after the series value.
**kwargs
Expand Down