-
-
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
Changes from 10 commits
6480b22
6a643fc
e4dbd78
5523dd5
c83eff0
04dbd04
4f73176
35ce553
0279ae8
d8fe91d
2dd734c
e010c13
34b4e99
932feff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,48 @@ class DatetimeProperties(Properties): | |
""" | ||
|
||
def to_pydatetime(self): | ||
""" | ||
Return an ndarray of native Python datetime objects. | ||
|
||
Timezone information is retained if present. | ||
|
||
.. warning:: | ||
|
||
Python's datetimes use microsecond resolution, which is lower than | ||
pandas' (nanosecond). The values are truncated. | ||
|
||
Returns | ||
------- | ||
numpy.ndarray | ||
object dtype array containing native Python datetime objects. | ||
|
||
See Also | ||
-------- | ||
datetime.datetime : Standard library value for a datetime. | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. head can be removed |
||
0 2018-03-10 | ||
1 2018-03-11 | ||
dtype: datetime64[ns] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @datapythonista , There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed it by just using >>> s There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just do |
||
|
||
>>> s.dt.to_pydatetime() | ||
array([datetime.datetime(2018, 3, 10, 0, 0), | ||
datetime.datetime(2018, 3, 11, 0, 0)], dtype=object) | ||
|
||
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 commentThe 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 commentThe 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 commentThe 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 |
||
>>> idx | ||
DatetimeIndex(['2017-01-01 00:00:00', '2017-01-01 00:00:00.000000001'], | ||
dtype='datetime64[ns]', freq='N') | ||
|
||
>>> idx.to_pydatetime() | ||
array([datetime.datetime(2017, 1, 1, 0, 0), | ||
datetime.datetime(2017, 1, 1, 0, 0)], dtype=object) | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
return self._get_values().to_pydatetime() | ||
|
||
@property | ||
|
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'd use something like "Return the data as native Python datetime objects".
The context helps, but the way is written makes me feel more like it's returning an empty or random array, not transforming data.