From edaeca27889df8119525a60a234ce7f58c2a125f Mon Sep 17 00:00:00 2001 From: omkar Date: Sat, 3 Sep 2022 17:03:56 +0530 Subject: [PATCH 1/4] doc update for #47134 --- pandas/core/tools/datetimes.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 203a5711b7a59..3ed21b83796e2 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -777,11 +777,18 @@ def to_datetime( #time-zone-handling>`_. format : str, default None - The strftime to parse time, e.g. :const:`"%d/%m/%Y"`. Note that - :const:`"%f"` will parse all the way up to nanoseconds. See + The strftime to parse time, e.g. :const:`"%d/%m/%Y"`. See `strftime documentation `_ for more information on choices. + + - Note that :const:`"%f"` will parse all the way + up to nanoseconds. + + - Note that :const:`"%S"` without :const:`"%f"` will capture all the way + up to nanoseconds if present as decimal places, but will also handle + the case where the number of seconds is an integer. + exact : bool, default True Control how `format` is used: @@ -950,6 +957,21 @@ def to_datetime( DatetimeIndex(['1960-01-02', '1960-01-03', '1960-01-04'], dtype='datetime64[ns]', freq=None) + **Exceptions to strptime behavior** + + :const:`"%f"` will parse all the way up to nanoseconds. + + >>> pd.to_datetime('2018-10-26 12:00:00.0000000011', + ... format='%Y-%m-%d %H:%M:%S.%f') + Timestamp('2018-10-26 12:00:00.000000001') + + :const:`"%S"` without :const:`"%f"` will capture all the way + up to nanoseconds if present as decimal places. + + >>> pd.to_datetime('2017-03-22 15:16:45.433502912', + ... format='%Y-%m-%d %H:%M:%S') + Timestamp('2017-03-22 15:16:45.433502912') + **Non-convertible date/times** If a date does not meet the `timestamp limitations From d1d0c0ad4649a83a2f080aa5513c4f0ad9fb9832 Mon Sep 17 00:00:00 2001 From: omkar Date: Sat, 3 Sep 2022 17:38:19 +0530 Subject: [PATCH 2/4] black and trailing spaces fixed --- pandas/core/tools/datetimes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 3ed21b83796e2..430d0d9b5177e 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -960,7 +960,7 @@ def to_datetime( **Exceptions to strptime behavior** :const:`"%f"` will parse all the way up to nanoseconds. - + >>> pd.to_datetime('2018-10-26 12:00:00.0000000011', ... format='%Y-%m-%d %H:%M:%S.%f') Timestamp('2018-10-26 12:00:00.000000001') From d8f1612bf29618342ebcca7e2f30967a753d0609 Mon Sep 17 00:00:00 2001 From: Omkar Yadav <35161288+heroesIV@users.noreply.github.com> Date: Sat, 3 Sep 2022 18:54:38 +0530 Subject: [PATCH 3/4] rewording_1 #48376 Co-authored-by: Marco Edward Gorelli --- pandas/core/tools/datetimes.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 430d0d9b5177e..0c459e8f34fc6 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -780,13 +780,14 @@ def to_datetime( The strftime to parse time, e.g. :const:`"%d/%m/%Y"`. See `strftime documentation `_ for more information on choices. + #strftime-and-strptime-behavior>`_ for more information on choices, though + note the following differences: - - Note that :const:`"%f"` will parse all the way - up to nanoseconds. + - :const:`"%f"` will parse all the way + up to nanoseconds; - - Note that :const:`"%S"` without :const:`"%f"` will capture all the way - up to nanoseconds if present as decimal places, but will also handle + - :const:`"%S"` without :const:`"%f"` will capture all the way + up to nanoseconds if present as decimal places, and will also handle the case where the number of seconds is an integer. exact : bool, default True From 0273713c6d6528af5f4db8459810368273027fa3 Mon Sep 17 00:00:00 2001 From: Omkar Yadav <35161288+heroesIV@users.noreply.github.com> Date: Sat, 3 Sep 2022 18:54:58 +0530 Subject: [PATCH 4/4] rewording_2 #48376 Co-authored-by: Marco Edward Gorelli --- pandas/core/tools/datetimes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 0c459e8f34fc6..78e12c96ceee8 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -958,7 +958,7 @@ def to_datetime( DatetimeIndex(['1960-01-02', '1960-01-03', '1960-01-04'], dtype='datetime64[ns]', freq=None) - **Exceptions to strptime behavior** + **Differences with strptime behavior** :const:`"%f"` will parse all the way up to nanoseconds.