-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Improve the docstring of DataFrame.transpose() #20254
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
DOC: Improve the docstring of DataFrame.transpose() #20254
Conversation
See Also | ||
-------- | ||
numpy.transpose : Permute the dimensions of a given array. | ||
|
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.
Another recommendation to include in the See Also section:
DataFrame.T: alias for DataFrame.transpose
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.
That's a good idea, the only problem with that is that we use the same docstring for .T
, so then it would be pointing to itself.
So I would just reflect the full docstring for both, like you already did in the examples.
@igorcadelima maybe add in the extended summary that it is both as method transpose() and property T
pandas/core/frame.py
Outdated
0 1 | ||
col1 1 2 | ||
col2 3 4 | ||
""" |
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.
Fantastic to see the usage of both T and transpose!
If possible, please add an example with a non-square DataFrame, e.g. 2 rows and 5 columns to show off some functionality - or maybe add some information about the fact it can be applied to square and non-square DataFrames?
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.
Done. How do you like it now? :)
pandas/core/frame.py
Outdated
---------- | ||
*args | ||
These arguments will be passed to | ||
:func:`pandas.compat.numpy.function.validate_transpose`. |
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.
@jorisvandenbossche I think standard for this has changed? we don't need to mention the internal functions here
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.
Yes, the explanation we are using in other PRs is "Additional keywords have no effect but might be accepted for compatibility with numpy".
@igorcadelima and you can put both on a single line, like:
*args, **kwargs
Additional keywords have no effect but might be accepted for
compatibility with numpy
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.
Thanks for the comments!
The reason I didn't just use "Additional keywords have no effect but might be accepted for compatibility with numpy" is because there will be noticeable effects if we pass copy=True
.
In [1]: import pandas as pd
In [2]: d = {'col1': [1, 2], 'col2': [3, 4]}
In [3]: df = pd.DataFrame(d)
In [4]: df
Out[4]:
col1 col2
0 1 3
1 2 4
In [5]: df2 = df.transpose() # or df.T
In [6]: df2
Out[6]:
0 1
col1 1 2
col2 3 4
In [7]: df3 = df.transpose(copy=True)
In [8]: df3
Out[8]:
0 1
col1 1 2
col2 3 4
In [9]: df['col1'] = 10
In [10]: df
Out[10]:
col1 col2
0 10 3
1 10 4
In [11]: df2
Out[11]:
0 1
col1 10 10
col2 3 4
In [12]: df3
Out[12]:
0 1
col1 1 2
col2 3 4
copy
is the only keyword I have found to have any effect on the transpose operation. What do you think I should do in this case, @jorisvandenbossche @jreback ?
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.
But copy is not a numpy keyword? https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.transpose.html
So I think we should actually just document copy
as an actual keyword (although it is not in the signature, for technical reasons, and so the validation script will complain about that, but you can ignore that)
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.
pandas/core/frame.py
Outdated
**kwargs | ||
Keyword arguments used to create the transposed DataFrame. | ||
|
||
Returns |
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.
can you also add an example with a mixed dtypes, and show the dtypes before/after. and add in the Notes section how transposing can change the dtypes.
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.
Hi, @jreback . I've made some changes to incorporate your suggestion.
Codecov Report
@@ Coverage Diff @@
## master #20254 +/- ##
=======================================
Coverage 91.84% 91.84%
=======================================
Files 152 152
Lines 49231 49231
=======================================
Hits 45215 45215
Misses 4016 4016
Continue to review full report at Codecov.
|
c4a06fe
to
d8568f1
Compare
Co-authored-by: Carlos Eduardo Moreira dos Santos <[email protected]> Signed-off-by: Igor C. A. de Lima <[email protected]> Signed-off-by: Carlos Eduardo Moreira dos Santos <[email protected]>
Co-authored-by: Carlos Eduardo Moreira dos Santos <[email protected]> Signed-off-by: Igor C. A. de Lima <[email protected]> Signed-off-by: Carlos Eduardo Moreira dos Santos <[email protected]>
Signed-off-by: Igor C. A. de Lima <[email protected]>
d8568f1
to
3954675
Compare
Signed-off-by: Igor C. A. de Lima <[email protected]>
Signed-off-by: Igor C. A. de Lima <[email protected]>
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.
Very nice updates! Looking good
(I only made a small clarification of the |
@igorcadelima @cemsbr Thanks for the PR! |
* DOC: Improve the docstring of DataFrame.transpose() Co-authored-by: Carlos Eduardo Moreira dos Santos <[email protected]>
* DOC: Improve the docstring of DataFrame.transpose() Co-authored-by: Carlos Eduardo Moreira dos Santos <[email protected]>
* DOC: Improve the docstring of DataFrame.transpose() Co-authored-by: Carlos Eduardo Moreira dos Santos <[email protected]>
Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):
scripts/validate_docstrings.py <your-function-or-method>
git diff upstream/master -u -- "*.py" | flake8 --diff
python doc/make.py --single <your-function-or-method>
Please include the output of the validation script below between the "```" ticks:
The errors are well-known false positives.