From 26338e9cc87d1211155b7f7e24a8f72149df7199 Mon Sep 17 00:00:00 2001 From: Tushar Date: Sat, 10 Mar 2018 14:31:35 +0530 Subject: [PATCH 1/3] Add docstring for DatetimeIndex.strftime method --- pandas/core/indexes/datetimelike.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index e673bfe411cb4..61a173e7b02ac 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -61,6 +61,8 @@ 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. + 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}>`__ @@ -68,11 +70,30 @@ def strftime(self, date_format): 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 + + 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. + + 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' """.format("https://docs.python.org/3/library/datetime.html" "#strftime-and-strptime-behavior") From 7f01a2c69a28d67e709862de354e6f25647c6800 Mon Sep 17 00:00:00 2001 From: Tushar Date: Sat, 10 Mar 2018 14:52:01 +0530 Subject: [PATCH 2/3] Typo in docstring --- pandas/core/indexes/datetimelike.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 61a173e7b02ac..7df880f49f4a2 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -75,7 +75,7 @@ def strftime(self, date_format): Returns ------- numpy.ndarray - n dimensional array of formatted strings + n-dimensional array of formatted strings See Also -------- From 8decfa746a80f971b6549e91432963cab4d53943 Mon Sep 17 00:00:00 2001 From: Tushar Date: Sat, 10 Mar 2018 19:30:52 +0530 Subject: [PATCH 3/3] Updated docstring for DatetimeIndex.strftime method --- pandas/core/indexes/datetimelike.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 7df880f49f4a2..dae5324da41be 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -61,7 +61,7 @@ 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. + Convert to string array using specified date_format. Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library. Details @@ -75,25 +75,27 @@ def strftime(self, date_format): Returns ------- numpy.ndarray - n-dimensional array of formatted strings + NumPy array of formatted strings See Also -------- + pandas.to_datetime : Convert the given argument to datetime 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. Examples -------- - >>> data = ['2015-05-01 18:47:05.060000','2014-05-01 18:47:05.110000'] + >>> import datetime + >>> data = pd.date_range(datetime.datetime(2018,3,10,19,27,52), + ... periods=4, freq='B') >>> df = pd.DataFrame(data, columns=['date']) - >>> df.date = pd.to_datetime(df.date) >>> df.date[1] - Timestamp('2014-05-01 18:47:05.110000') + Timestamp('2018-03-13 19:27:52') >>> df.date[1].strftime('%d-%m-%Y') - '01-05-2014' + '13-03-2018' >>> df.date[1].strftime('%B %d, %Y, %r') - 'May 01, 2014, 06:47:05 PM' + 'March 13, 2018, 07:27:52 PM' """.format("https://docs.python.org/3/library/datetime.html" "#strftime-and-strptime-behavior")