Skip to content

Docstring changes to pandas.Series.dt.to_pydatetime #20198

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

Conversation

priya-gitTest
Copy link
Contributor

@priya-gitTest priya-gitTest 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:

scripts/validate_docstrings.py pandas.Series.dt.to_pydatetime

Errors found:
        No extended summary found

Extended Summary removed as per Reviewers suggestion.


Checklist for other PRs (remove this part if you are doing a PR for the pandas documentation sprint):

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

@pep8speaks
Copy link

pep8speaks commented Mar 10, 2018

Hello @priya-gitTest! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on March 13, 2018 at 10:52 Hours UTC

@priya-gitTest priya-gitTest reopened this Mar 10, 2018
@priya-gitTest priya-gitTest changed the title PO: made docstring changes to pandas.Series.dt.to_pydatetime Docstring changes to pandas.Series.dt.to_pydatetime Mar 10, 2018
@priya-gitTest
Copy link
Contributor Author

fixed the PEP8 issues

@priya-gitTest priya-gitTest reopened this Mar 10, 2018
@@ -126,6 +126,32 @@ class DatetimeProperties(Properties):
"""

def to_pydatetime(self):
"""
Return DatetimeIndex as object ndarray of datetime.datetime objects.
Copy link
Contributor

Choose a reason for hiding this comment

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

Return DatetimeIndex as an object ndarray

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. Fixed it.

"""
Return DatetimeIndex as object ndarray of datetime.datetime objects.

This function converts the Pandas Series DatetimeIndex to
Copy link
Contributor

Choose a reason for hiding this comment

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

would remove this extended summary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


Returns
-------
datetimes : ndarray
Copy link
Contributor

Choose a reason for hiding this comment

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

ndarray of object dtype

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


See Also
--------
pd.DatetimeIndex.to_pydatetime : Convert a Timestamp object to a native
Copy link
Contributor

Choose a reason for hiding this comment

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

pandas.DatetimeIndex.to_pydatetime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

--------
pd.DatetimeIndex.to_pydatetime : Convert a Timestamp object to a native
Python datetime object.
pd.date.dt.values.to_datetime : For an Index containing strings or
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this 2nd part which is not valid

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


Examples
--------
>>> df = pd.DataFrame({'date': [pd.to_datetime('2018-03-10'), pd.to_datetime('2017-02-01')]})
Copy link
Contributor

Choose a reason for hiding this comment

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

make a series like: In [1]: Series(pd.date_range('20180310', periods=2))
show its return, then show the return of using .dt.to_pytdatetime()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@jreback jreback added Docs Datetime Datetime data dtype labels Mar 10, 2018
@TomAugspurger
Copy link
Contributor

@priya-gitTest I think you replied to all of Jeff's comments. Make sure to push your changes when you're ready :)

@priya-gitTest
Copy link
Contributor Author

Have pushed the changes. Can you Review them @jreback

@@ -126,6 +126,26 @@ class DatetimeProperties(Properties):
"""

def to_pydatetime(self):
"""
Return DatetimeIndex as an object ndarray.
Copy link
Member

Choose a reason for hiding this comment

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

I would mention it is an array of "native Python datetime objects" ?

Copy link
Member

@jorisvandenbossche jorisvandenbossche Mar 10, 2018

Choose a reason for hiding this comment

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

Can you change this to "Return Series" instead of "Return DatetimeIndex" (as it is the accessor on a 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.

done, Kindly review


See Also
--------
pandas.DatetimeIndex.to_pydatetime : Convert a Timestamp object to a native
Copy link
Member

Choose a reason for hiding this comment

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

This is now referencing itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah, sorry! Missed that this one was in accessors.py.

>>> df = pd.Series(pd.date_range('20180310', periods=2))
>>> type(df)
<class 'pandas.core.series.Series'>
>>> type(df.dt.to_pydatetime())
Copy link
Member

Choose a reason for hiding this comment

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

I would actually show the output here, instead of inspecting the type (that will also show it is an array, but also show it holds datetime.datetime objects)


Examples
--------
>>> df = pd.Series(pd.date_range('20180310', periods=2))
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 call this s instead of df (since it is a Series)

--------
>>> df = pd.Series(pd.date_range('20180310', periods=2))
>>> type(df)
<class 'pandas.core.series.Series'>
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed I think


Returns
-------
ndarray of object dtype
Copy link
Member

Choose a reason for hiding this comment

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

-> Series of object dtype

@jorisvandenbossche
Copy link
Member

@priya-gitTest Updated some of my comments reflecting this is in accessors.py (and not the DatetimeIndex version). The other comments still stand though

@priya-gitTest
Copy link
Contributor Author

Done, Kindly review

@jreback jreback added this to the 0.23.0 milestone Mar 11, 2018
@jreback
Copy link
Contributor

jreback commented Mar 11, 2018

lgtm. @jorisvandenbossche @TomAugspurger I am fine that the accessors look this way. possibly could add a pure index example as well.

@TomAugspurger
Copy link
Contributor

FYI, this returns an ndarray, not a series or datetimeindex. Fixing up now.

>>> idx.to_pydatetime()
array([datetime.datetime(2018, 3, 10, 0, 0),
datetime.datetime(2018, 3, 11, 0, 0)], dtype=object)
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

I gave up on a tz example since the repr for datetime w/ tz is so long. Wasn't able to make it look nice.

@TomAugspurger
Copy link
Contributor

Thanks @priya-gitTest are you able to pull my changes and make these last few recommendations?

@priya-gitTest
Copy link
Contributor Author

Hi @TomAugspurger , I will try to pull and fix changes suggested by @datapythonista

@priya-gitTest
Copy link
Contributor Author

Pushed the fixes. Kindly check !!!

@datapythonista
Copy link
Member

Sorry, seems like you pushed many commits unrelated to this PR. Can you take a look?

@priya-gitTest
Copy link
Contributor Author

priya-gitTest commented Mar 11, 2018

Hi datapythonista,

I had to reset my master. That might be the cause as l had some local changes another DocString changes :(

I had done
git reset --hard HEAD
git clean -f
git pull

Will see , if i can do something about it :(

@datapythonista
Copy link
Member

I'd say that in general you can just get the new changes to your branch by:

git checkout <your-branch>
git fetch upstream
git merge upstream/master

It may be a bit tricky now. I'd do a manual copy of your docstring somewhere else, before playing too much with git. :)

@priya-gitTest
Copy link
Contributor Author

Thanks Marc. Resolving GIT issues are indeed tricky. I did used those steps but i wanted to work on another function and it had an un-commited file changes , hence some errors ...

@priya-gitTest
Copy link
Contributor Author

Found this one for future http://blog.dennisrobinson.name/push-only-one-commit-with-git/.
Not going to play around with this on this branch ;)

@priya-gitTest priya-gitTest force-pushed the docstring_series_to_pydatetime branch from 28d5a8a to 35ce553 Compare March 11, 2018 21:24
@TomAugspurger
Copy link
Contributor

Removedd the references to DatetimeIndex. Sorry about messing that up intitially @priya-gitTest.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Mar 12, 2018

Ah one thing I just thought of, we should add a warning about nanosecond-precision data not being supported by python's datetime.datetime.

In [13]: idx = pd.date_range('2017', periods=4, freq='ns')

In [14]: idx
Out[14]:
DatetimeIndex([          '2017-01-01 00:00:00',
               '2017-01-01 00:00:00.000000001',
               '2017-01-01 00:00:00.000000002',
               '2017-01-01 00:00:00.000000003'],
              dtype='datetime64[ns]', freq='N')

In [15]: idx.to_pydatetime()
Out[15]:
array([datetime.datetime(2017, 1, 1, 0, 0),
       datetime.datetime(2017, 1, 1, 0, 0),
       datetime.datetime(2017, 1, 1, 0, 0),
       datetime.datetime(2017, 1, 1, 0, 0)], dtype=object)

@priya-gitTest do you want to handle that? It should probably go in a ..warning box right after the note about timezone info being retained, and as an example.

@priya-gitTest
Copy link
Contributor Author

Hi @TomAugspurger , I would have loved to fix it but i have messed up my local GIT repository. I could only undo upto your good changes of 35ce553 . Whenever i pull or push , i have merge conflicts and i don't want to push other people's changes via my PUSH. So, just let me know when i can close or delete my branch.

@datapythonista
Copy link
Member

@priya-gitTest I think your branch looks all right now. May be I'm missing something, but I'd say that:

git checkout docstring_series_to_pydatetime
git pull
git fetch upstream
git merge upstream/master

shouldn't give you any conflict, and leave your changes with the latest version.

Otherwise, you can always do a new git clone, in a different directory, create a branch with the same name, change manually the docstring there, commit, and push to the remote branch (I think git push -u -f origin docstring_series_to_pydatetime should do the trick).


pandas' nanosecond precision is truncated to microseconds.

>>> idx = pd.date_range('2017', periods=2, freq='ns')
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 use a Series example here?

Copy link
Contributor Author

@priya-gitTest priya-gitTest Mar 13, 2018

Choose a reason for hiding this comment

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

nanosec
Btw, I dont get the same output as you @TomAugspurger for the nanosecond-precision data in the jupyter notebook.
I run my code on Windows !
Strangely the docstring Validation test passes, so it must be going right.

Copy link
Contributor

Choose a reason for hiding this comment

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

Strange, not sure why that would be.

Are you able to wrap that in a Series and do ser.dt.to_pydatetimte()? I'll it once you update.

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Mar 12, 2018

And there's always the nuclear option of git reset --hard <branch> so git reset --hard origin/ docstring_series_to_pydatetime in this case. But that throws away local changes.

Examples
--------
>>> s = pd.Series(pd.date_range('20180310', periods=2))
>>> s.head()
Copy link
Member

Choose a reason for hiding this comment

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

head can be removed

@priya-gitTest
Copy link
Contributor Author

Thanks all. I will give it a shot in a while and keep you
posted :)

@priya-gitTest
Copy link
Contributor Author

kindly review @jorisvandenbossche @TomAugspurger

@codecov
Copy link

codecov bot commented Mar 13, 2018

Codecov Report

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

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #20198   +/-   ##
=======================================
  Coverage   91.72%   91.72%           
=======================================
  Files         150      150           
  Lines       49165    49165           
=======================================
  Hits        45099    45099           
  Misses       4066     4066
Flag Coverage Δ
#multiple 90.11% <ø> (ø) ⬆️
#single 41.86% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/indexes/accessors.py 90.19% <ø> (ø) ⬆️

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 31afaf8...932feff. Read the comment docs.

Copy link
Member

@jorisvandenbossche jorisvandenbossche 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 updates, looks good now!

@jorisvandenbossche jorisvandenbossche merged commit 0cd5c5c into pandas-dev:master Mar 13, 2018
@jorisvandenbossche
Copy link
Member

And thanks for the PR! @priya-gitTest

@priya-gitTest
Copy link
Contributor Author

Thanks everyone here again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Datetime Datetime data dtype Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants