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

Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ class DatetimeProperties(Properties):
"""

def to_pydatetime(self):
"""
Return Series as a native Python datetime objects.

Returns
-------
Series of object dtype

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.

Python datetime object.

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

0 2018-03-10
1 2018-03-11
dtype: datetime64[ns]
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary head().

Copy link
Contributor Author

@priya-gitTest priya-gitTest Mar 11, 2018

Choose a reason for hiding this comment

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

Hi @datapythonista ,
If I remove the head, the validation test fails.
Line 18, in pandas.Series.dt.to_pydatetime
Failed example:
s = pd.Series(pd.date_range('20180310', periods=2))
Expected:
0 2018-03-10
1 2018-03-11
dtype: datetime64[ns]
Got nothing

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 it by just using >>> s

Copy link
Contributor

Choose a reason for hiding this comment

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

You can just do s by itself.

>>> s.dt.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.

return self._get_values().to_pydatetime()

@property
Expand Down