Skip to content

DOC: update the DataFrame.applymap docstring #20136

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
Mar 16, 2018

Conversation

orereta
Copy link
Contributor

@orereta orereta commented Mar 10, 2018

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • PR title is "DOC: update the docstring"
  • The validation script passes: scripts/validate_docstrings.py <your-function-or-method>
  • The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • The html version looks good: python doc/make.py --single <your-function-or-method>
  • It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

python scripts/validate_docstrings.py pandas.DataFrame.applymap

################################################################################
#################### Docstring (pandas.DataFrame.applymap)  ####################
################################################################################

Apply a function to a Dataframe elementwise.

This method applies a function to a DataFrame that is intended to
operate elementwise, i.e. like doing `map(func, series)` for each
series in the DataFrame.

Parameters
----------
func : function
    Python function, returns a single value from a single value.

Returns
-------
pandas.DataFrame
    A transformed DataFrame.

See also
--------
DataFrame.apply : Apply a function along input axis of DataFrame

Examples
--------
>>> df = pd.DataFrame([[1.,2.], [3.,4.]])
>>> df
     0    1
0  1.0  2.0
1  3.0  4.0
>>> df = df.applymap(lambda x: x**2)
>>> df
     0     1
0  1.0   4.0
1  9.0  16.0

################################################################################
################################## Validation ##################################
################################################################################

Docstring for "pandas.DataFrame.applymap" correct. :)

Apply a function to a DataFrame that is intended to operate
elementwise, i.e. like doing map(func, series) for each series in the
DataFrame
Apply a function to a Dataframe elementwise.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a "elementwise function" or a "scalar function", I'm not sure.

Apply a function to a Dataframe elementwise.

This method applies a function to a DataFrame that is intended to
operate elementwise, i.e. like doing map(func, series) for each series
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably mark it as code `map(func, series)`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks! addressed


Returns
-------
applied : DataFrame
pandas.DataFrame
A transformed DataFrame.
Copy link
Contributor

Choose a reason for hiding this comment

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

Possibly, remove the "A" .


>>> df = pd.DataFrame(np.random.RandomState(0).randn(3, 3))

Choose a reason for hiding this comment

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

In the Conventions for the examples mentions:

avoid using data without interpretation, like a matrix of random numbers with columns A, B, C, D… And instead use a meaningful example, which makes it easier to understand the concept

In fact, this one looks like the Bad example :-P

I'd suggest improving this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the comment, actually we updated previous random example to a deterministic one by hardcoding the random seed through RandomState(0). Since we are illustrating an elementwise mapping it might be easier to use a matrix [[1,2],[3,4]] and square it.

@codecov
Copy link

codecov bot commented Mar 16, 2018

Codecov Report

Merging #20136 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #20136      +/-   ##
==========================================
- Coverage   91.72%    91.7%   -0.03%     
==========================================
  Files         150      150              
  Lines       49156    49152       -4     
==========================================
- Hits        45090    45074      -16     
- Misses       4066     4078      +12
Flag Coverage Δ
#multiple 90.08% <ø> (-0.03%) ⬇️
#single 41.84% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/frame.py 97.18% <ø> (ø) ⬆️
pandas/plotting/_converter.py 65.07% <0%> (-1.74%) ⬇️
pandas/core/base.py 96.78% <0%> (-0.02%) ⬇️
pandas/core/series.py 93.85% <0%> (-0.01%) ⬇️
pandas/core/indexes/base.py 96.66% <0%> (-0.01%) ⬇️
pandas/core/indexes/multi.py 95.06% <0%> (ø) ⬆️
pandas/core/generic.py 95.84% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 840d432...26c5aa8. Read the comment docs.

@TomAugspurger TomAugspurger added this to the 0.23.0 milestone Mar 16, 2018
@TomAugspurger
Copy link
Contributor

Thanks @orereta !

@TomAugspurger TomAugspurger merged commit 3561580 into pandas-dev:master Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants