-
-
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
DOC: fix Dataframe.to_records examples #22419
DOC: fix Dataframe.to_records examples #22419
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.
Thanks for the fixes. If you want, you can also replace in this PR, boolean
by bool
in the parameters types, remove the y
in Returns
and just leave the type, and add a description of what is returned in the next line.
This way the docstring will follow all the standards.
Thanks!
pandas/core/frame.py
Outdated
|
||
>>> df.to_records(convert_datetime64=False) | ||
rec.array([('2018-01-01T09:00:00.000000000', 1, 0.5 ), | ||
('2018-01-01T09:01:00.000000000', 2, 0.75)], | ||
dtype=[('index', '<M8[ns]'), ('A', '<i8'), ('B', '<f8')]) | ||
|
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.
As convert_datetime64
is now deprecated, I'd get rid of the examples for it. I feel like they encourage writing code that will be broken soon.
Also, do you mind removing the blank lines before and after the closing """
of the docstring?
Codecov Report
@@ Coverage Diff @@
## master #22419 +/- ##
=======================================
Coverage 92.05% 92.05%
=======================================
Files 169 169
Lines 50733 50733
=======================================
Hits 46702 46702
Misses 4031 4031
Continue to review full report at Codecov.
|
Changes made, as requested. I also added an example of what happens when the index of the dataframe is given a label. As expected, the attribute of the recarray is named using the label of the index, but I thought it was ambiguous from the docs what might happen. |
pandas/core/frame.py
Outdated
is set to 'index'. If the index has a label then this is used as the | ||
field name: | ||
|
||
>>> df.index.rename("I", inplace=True) |
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.
don't use inplace in examples, pls just reassign the index
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!
… DataFrame.to_records
* Fixed incorrect case in DataFrame * Changed 'attributes' to 'fields' when describing recarray features * Improved description of how the index is set in the recarray
@@ -21,7 +21,7 @@ if [ "$DOCTEST" ]; then | |||
|
|||
# DataFrame / Series docstrings | |||
pytest --doctest-modules -v pandas/core/frame.py \ | |||
-k"-assign -axes -combine -isin -itertuples -join -nlargest -nsmallest -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_dict -to_records -to_stata -transform" | |||
-k"-assign -axes -combine -isin -itertuples -join -nlargest -nsmallest -nunique -pivot_table -quantile -query -reindex -reindex_axis -replace -round -set_index -stack -to_dict -to_stata -transform" |
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.
is this on-purpose?
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.
I was asked to make this change by @TomAugspurger in issue #18160. I believe the point is to check that the examples are correct.
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 is a whitelist of doctests that are allowed to fail till we fix them.
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.
Yep, going to open an issue about this
thanks @H0R5E @pandas-dev/pandas-core merge on green. |
Happy to help. Keep up the great work! |
Thanks for the contribution @H0R5E |
git diff upstream/master -u -- "*.py" | flake8 --diff
Fixed the examples of Dataframe.to_records related to timestamp conversion following the changes in default behaviour made in pull request #18902. As requested in issue #18160.