Skip to content

Doc: Update the DatetimeIndex.strftime docstring #20103

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
merged 3 commits into from
Mar 13, 2018
Merged
Changes from 2 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
25 changes: 23 additions & 2 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,39 @@ def strftime(self, date_format):
return np.asarray(self.format(date_format=date_format),
dtype=compat.text_type)
strftime.__doc__ = """
Convert to specified date_format.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe mention it is converted to a string?


Return an array of formatted strings specified by date_format, which
supports the same string format as the python standard library. Details
of the string format can be found in `python string format doc <{0}>`__

Parameters
----------
date_format : str
date format string (e.g. "%Y-%m-%d")
Date format string (e.g. "%Y-%m-%d").

Returns
-------
ndarray of formatted strings
numpy.ndarray
n-dimensional array of formatted strings
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 just say "NumPy array" instead of "n-dimensional", as it is always 1D

Copy link
Contributor

Choose a reason for hiding this comment

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

@jorisvandenbossche separate issue, this should actually return an Index here.


See Also
--------
DatetimeIndex.normalize : Return DatetimeIndex with times to midnight.
DatetimeIndex.round : Round the DatetimeIndex to the specified freq.
DatetimeIndex.floor : Floor the DatetimeIndex to the specified freq.
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 also link to the similar conversion but other way around: to_datetime


Examples
--------
>>> data = ['2015-05-01 18:47:05.060000','2014-05-01 18:47:05.110000']
>>> df = pd.DataFrame(data, columns=['date'])
>>> df.date = pd.to_datetime(df.date)
>>> df.date[1]
Timestamp('2014-05-01 18:47:05.110000')
>>> df.date[1].strftime('%d-%m-%Y')
'01-05-2014'
>>> df.date[1].strftime('%B %d, %Y, %r')
'May 01, 2014, 06:47:05 PM'
Copy link
Member

Choose a reason for hiding this comment

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

The docstring is from DatetimeIndex. Can you update the example to use that? (so eg create an example dataframe with DatetimeIndex with eg pd.date_range)

""".format("https://docs.python.org/3/library/datetime.html"
"#strftime-and-strptime-behavior")

Expand Down