-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Docstring changes to pandas.Series.dt.to_pydatetime #20198
Conversation
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 |
fixed the PEP8 issues |
pandas/core/indexes/accessors.py
Outdated
@@ -126,6 +126,32 @@ class DatetimeProperties(Properties): | |||
""" | |||
|
|||
def to_pydatetime(self): | |||
""" | |||
Return DatetimeIndex as object ndarray of datetime.datetime objects. |
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.
Return DatetimeIndex as an object ndarray
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. Fixed it.
pandas/core/indexes/accessors.py
Outdated
""" | ||
Return DatetimeIndex as object ndarray of datetime.datetime objects. | ||
|
||
This function converts the Pandas Series DatetimeIndex to |
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.
would remove this extended summary
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.
Fixed.
pandas/core/indexes/accessors.py
Outdated
|
||
Returns | ||
------- | ||
datetimes : ndarray |
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.
ndarray of object dtype
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.
Fixed.
pandas/core/indexes/accessors.py
Outdated
|
||
See Also | ||
-------- | ||
pd.DatetimeIndex.to_pydatetime : Convert a Timestamp object to a native |
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.DatetimeIndex.to_pydatetime
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.
Fixed.
pandas/core/indexes/accessors.py
Outdated
-------- | ||
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 |
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.
remove this 2nd part which is not valid
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.
Fixed.
pandas/core/indexes/accessors.py
Outdated
|
||
Examples | ||
-------- | ||
>>> df = pd.DataFrame({'date': [pd.to_datetime('2018-03-10'), pd.to_datetime('2017-02-01')]}) |
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.
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()
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.
Fixed.
@priya-gitTest I think you replied to all of Jeff's comments. Make sure to push your changes when you're ready :) |
Have pushed the changes. Can you Review them @jreback |
pandas/core/indexes/accessors.py
Outdated
@@ -126,6 +126,26 @@ class DatetimeProperties(Properties): | |||
""" | |||
|
|||
def to_pydatetime(self): | |||
""" | |||
Return DatetimeIndex as an object ndarray. |
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 would mention it is an array of "native Python datetime objects" ?
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 change this to "Return Series" instead of "Return DatetimeIndex" (as it is the accessor on a Series) ?
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, Kindly review
pandas/core/indexes/accessors.py
Outdated
|
||
See Also | ||
-------- | ||
pandas.DatetimeIndex.to_pydatetime : Convert a Timestamp object to a native |
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 now referencing itself?
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.
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.
Ah, sorry! Missed that this one was in accessors.py
.
pandas/core/indexes/accessors.py
Outdated
>>> df = pd.Series(pd.date_range('20180310', periods=2)) | ||
>>> type(df) | ||
<class 'pandas.core.series.Series'> | ||
>>> type(df.dt.to_pydatetime()) |
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 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)
pandas/core/indexes/accessors.py
Outdated
|
||
Examples | ||
-------- | ||
>>> df = pd.Series(pd.date_range('20180310', periods=2)) |
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 call this s
instead of df
(since it is a Series)
pandas/core/indexes/accessors.py
Outdated
-------- | ||
>>> df = pd.Series(pd.date_range('20180310', periods=2)) | ||
>>> type(df) | ||
<class 'pandas.core.series.Series'> |
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 not needed I think
pandas/core/indexes/accessors.py
Outdated
|
||
Returns | ||
------- | ||
ndarray of object dtype |
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.
-> Series of object dtype
@priya-gitTest Updated some of my comments reflecting this is in accessors.py (and not the DatetimeIndex version). The other comments still stand though |
Done, Kindly review |
lgtm. @jorisvandenbossche @TomAugspurger I am fine that the accessors look this way. possibly could add a pure index example as well. |
FYI, this returns an ndarray, not a series or datetimeindex. Fixing up now. |
pandas/core/indexes/accessors.py
Outdated
>>> idx.to_pydatetime() | ||
array([datetime.datetime(2018, 3, 10, 0, 0), | ||
datetime.datetime(2018, 3, 11, 0, 0)], dtype=object) | ||
""" |
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 gave up on a tz example since the repr for datetime w/ tz is so long. Wasn't able to make it look nice.
Thanks @priya-gitTest are you able to pull my changes and make these last few recommendations? |
Hi @TomAugspurger , I will try to pull and fix changes suggested by @datapythonista |
Pushed the fixes. Kindly check !!! |
Sorry, seems like you pushed many commits unrelated to this PR. Can you take a look? |
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 Will see , if i can do something about it :( |
I'd say that in general you can just get the new changes to your branch by:
It may be a bit tricky now. I'd do a manual copy of your docstring somewhere else, before playing too much with git. :) |
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 ... |
Found this one for future http://blog.dennisrobinson.name/push-only-one-commit-with-git/. |
28d5a8a
to
35ce553
Compare
Removedd the references to DatetimeIndex. Sorry about messing that up intitially @priya-gitTest. |
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 |
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. |
@priya-gitTest I think your branch looks all right now. May be I'm missing something, but I'd say that:
shouldn't give you any conflict, and leave your changes with the latest version. Otherwise, you can always do a new |
pandas/core/indexes/accessors.py
Outdated
|
||
pandas' nanosecond precision is truncated to microseconds. | ||
|
||
>>> idx = pd.date_range('2017', periods=2, freq='ns') |
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 use a Series example 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.
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.
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.
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.
And there's always the nuclear option of |
pandas/core/indexes/accessors.py
Outdated
Examples | ||
-------- | ||
>>> s = pd.Series(pd.date_range('20180310', periods=2)) | ||
>>> s.head() |
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.
head can be removed
Thanks all. I will give it a shot in a while and keep you |
…riya-gitTest/pandas into docstring_series_to_pydatetime
kindly review @jorisvandenbossche @TomAugspurger |
Codecov Report
@@ Coverage Diff @@
## master #20198 +/- ##
=======================================
Coverage 91.72% 91.72%
=======================================
Files 150 150
Lines 49165 49165
=======================================
Hits 45099 45099
Misses 4066 4066
Continue to review full report at Codecov.
|
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 updates, looks good now!
And thanks for the PR! @priya-gitTest |
Thanks everyone here again :) |
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: