Skip to content

DOC: Removed Notes from DataFrame.applymap #31695

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
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
10 changes: 1 addition & 9 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6969,13 +6969,6 @@ def applymap(self, func) -> "DataFrame":
--------
DataFrame.apply : Apply a function along input axis of DataFrame.

Notes
-----
In the current implementation applymap calls `func` twice on the
Copy link
Member

Choose a reason for hiding this comment

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

is this no longer accurate? we regularly get questions about the user-defined functions being called in groupby.apply/agg to determine fast vs slow path

Copy link
Member

Choose a reason for hiding this comment

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

In #28854 this was removed from DataFrame.apply, and there are comments on the original issue (#28827) saying that the implementation has changed recently, and DataFrame.applymap directly calls DataFrame.apply

first column/row to decide whether it can take a fast or slow
code path. This can lead to unexpected behavior if `func` has
side-effects, as they will take effect twice for the first
column/row.

Examples
--------
Expand All @@ -6990,8 +6983,7 @@ def applymap(self, func) -> "DataFrame":
0 3 4
1 5 5

Note that a vectorized version of `func` often exists, which will
be much faster. You could square each number elementwise.
You could square each number elementwise.
Copy link
Member

Choose a reason for hiding this comment

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

This part doesn't need changing, the vectorised version is still faster:

In [28]: s = pd.Series(np.random.randn(10000))                                                                                                               

In [29]: %timeit s.apply(lambda x: x**2)                                                                                                                     
6.39 ms ± 5.73 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

In [30]: %timeit s**2                                                                                                                                        
243 µs ± 4.38 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

In [31]: pd.testing.assert_series_equal(s.apply(lambda x: x**2), s**2) 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh okay. Thanks a lot. Included it.

Copy link
Member

Choose a reason for hiding this comment

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

can you revert this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, for being late! I'm having a very busy semester. I'll do this asap and get back!


>>> df.applymap(lambda x: x**2)
0 1
Expand Down
22 changes: 21 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9960,7 +9960,7 @@ def _add_numeric_operations(cls):
see_also="",
examples="",
)
@Appender(_num_doc)
@Appender(_num_doc_mad)
def mad(self, axis=None, skipna=None, level=None):
if skipna is None:
skipna = True
Expand Down Expand Up @@ -10329,6 +10329,26 @@ def _doc_parms(cls):
%(examples)s
"""

_num_doc_mad = """
%(desc)s
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an unrelated change, can you revert


Parameters
----------
axis : %(axis_descr)s
Axis for the function to be applied on.
skipna : bool, default None
Exclude NA/null values when computing the result.
level : int or level name, default None
If the axis is a MultiIndex (hierarchical), count along a
particular level, collapsing into a %(name1)s.

Returns
-------
%(name1)s or %(name2)s (if level specified)\
%(see_also)s\
%(examples)s
"""

_num_ddof_doc = """
%(desc)s

Expand Down