From e6b9004f1c6f07e7607117e26bb8184af084dba3 Mon Sep 17 00:00:00 2001 From: Venkatesh Datta Date: Sat, 11 Apr 2020 04:19:36 +0530 Subject: [PATCH 1/5] DOC: timezone conversion example added to pandas.Series.astype doc #33399 --- pandas/core/generic.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index eb6554bf2260c..0c896a5cffedf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5538,6 +5538,24 @@ def astype( 0 10 1 2 dtype: int64 + + Create a series of dates: + + >>> ser_date = pd.Series(pd.date_range('20200101', periods=3)) + >>> ser_date + 0 2020-01-01 + 1 2020-01-02 + 2 2020-01-03 + dtype: datetime64[ns] + + Convert to datetime type with time zone: + + >>> # localize to UTC and convert to US/Eastern time zone + >>> ser_date.astype('datetime64[ns, US/Eastern]') + 0 2019-12-31 19:00:00-05:00 + 1 2020-01-01 19:00:00-05:00 + 2 2020-01-02 19:00:00-05:00 + dtype: datetime64[ns, US/Eastern] """ if is_dict_like(dtype): if self.ndim == 1: # i.e. Series From 293dfefbf48a5d48a6687cd8814dfbd6a35c4a27 Mon Sep 17 00:00:00 2001 From: Venkatesh Datta Date: Sat, 11 Apr 2020 04:43:21 +0530 Subject: [PATCH 2/5] DOC: fixed the whitespace issue flagged in pep8 checks #33399 --- pandas/core/generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0c896a5cffedf..0ac0f01ad9230 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5549,7 +5549,7 @@ def astype( dtype: datetime64[ns] Convert to datetime type with time zone: - + >>> # localize to UTC and convert to US/Eastern time zone >>> ser_date.astype('datetime64[ns, US/Eastern]') 0 2019-12-31 19:00:00-05:00 From 83647460bff69919de9a47f511e1af6207d7623a Mon Sep 17 00:00:00 2001 From: Venkatesh Datta Date: Sat, 11 Apr 2020 12:12:17 +0530 Subject: [PATCH 3/5] DOC: added text in comments to commentary in example #333999 --- pandas/core/generic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0ac0f01ad9230..73972aa4e15bf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5548,9 +5548,9 @@ def astype( 2 2020-01-03 dtype: datetime64[ns] - Convert to datetime type with time zone: + Convert to datetime type with time zone + (Behavior - Localize to UTC and convert to US/Eastern): - >>> # localize to UTC and convert to US/Eastern time zone >>> ser_date.astype('datetime64[ns, US/Eastern]') 0 2019-12-31 19:00:00-05:00 1 2020-01-01 19:00:00-05:00 From aecb9860207d1024a79b1bd493eb108be4be1f41 Mon Sep 17 00:00:00 2001 From: Venkatesh Datta Date: Sat, 11 Apr 2020 12:32:14 +0530 Subject: [PATCH 4/5] DOC: added a more generic behavior statement as suggested. #33399 --- pandas/core/generic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 73972aa4e15bf..07a1c49f3e4c9 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5549,7 +5549,8 @@ def astype( dtype: datetime64[ns] Convert to datetime type with time zone - (Behavior - Localize to UTC and convert to US/Eastern): + (Behavior - Datetimes are localized to UTC first + before converting to the specified timezone): >>> ser_date.astype('datetime64[ns, US/Eastern]') 0 2019-12-31 19:00:00-05:00 From 78458ebeafd8ecaae297f9aa4a398654b606b33f Mon Sep 17 00:00:00 2001 From: Venkatesh Datta Date: Sun, 12 Apr 2020 00:26:00 +0530 Subject: [PATCH 5/5] DOC: removed unwanted commentary statement as per suggestion #33399 --- pandas/core/generic.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 07a1c49f3e4c9..f5ebd6bc08bfb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -5548,9 +5548,8 @@ def astype( 2 2020-01-03 dtype: datetime64[ns] - Convert to datetime type with time zone - (Behavior - Datetimes are localized to UTC first - before converting to the specified timezone): + Datetimes are localized to UTC first before + converting to the specified timezone: >>> ser_date.astype('datetime64[ns, US/Eastern]') 0 2019-12-31 19:00:00-05:00