Skip to content
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

Merged
merged 9 commits into from
Aug 21, 2018
Merged

DOC: fix Dataframe.to_records examples #22419

merged 9 commits into from
Aug 21, 2018

Conversation

H0R5E
Copy link
Contributor

@H0R5E H0R5E commented Aug 19, 2018

  • closes #xxxx
  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff
  • whatsnew entry

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.

Copy link
Member

@datapythonista datapythonista left a 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!


>>> 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')])

Copy link
Member

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?

@datapythonista datapythonista added this to the 0.24.0 milestone Aug 19, 2018
@codecov
Copy link

codecov bot commented Aug 19, 2018

Codecov Report

Merging #22419 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #22419   +/-   ##
=======================================
  Coverage   92.05%   92.05%           
=======================================
  Files         169      169           
  Lines       50733    50733           
=======================================
  Hits        46702    46702           
  Misses       4031     4031
Flag Coverage Δ
#multiple 90.46% <ø> (ø) ⬆️
#single 42.24% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/frame.py 97.25% <ø> (ø) ⬆️

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 4f11d1a...140b04e. Read the comment docs.

@H0R5E
Copy link
Contributor Author

H0R5E commented Aug 19, 2018

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.

is set to 'index'. If the index has a label then this is used as the
field name:

>>> df.index.rename("I", inplace=True)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

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

is this on-purpose?

Copy link
Contributor Author

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.

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 a whitelist of doctests that are allowed to fail till we fix them.

Copy link
Member

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

@jreback
Copy link
Contributor

jreback commented Aug 20, 2018

thanks @H0R5E

@pandas-dev/pandas-core merge on green.

@H0R5E
Copy link
Contributor Author

H0R5E commented Aug 20, 2018

Happy to help. Keep up the great work!

@jorisvandenbossche jorisvandenbossche changed the title Fix Dataframe.to_records examples DOC: fix Dataframe.to_records examples Aug 20, 2018
@datapythonista datapythonista merged commit 68273a7 into pandas-dev:master Aug 21, 2018
@datapythonista
Copy link
Member

Thanks for the contribution @H0R5E

@H0R5E H0R5E deleted the fix_dataframe_to_records_examples branch August 21, 2018 13:14
Sup3rGeo pushed a commit to Sup3rGeo/pandas that referenced this pull request Oct 1, 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