From 5a75a01d95ae0e58f62aaf7431607e45192e28c5 Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 1 Nov 2020 10:22:00 -0500 Subject: [PATCH 1/8] Fix capitalization error in summary for Timestamp --- pandas/_libs/tslibs/timestamps.pyx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 9076325d01bab..2d747bce3e59d 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -912,7 +912,7 @@ class Timestamp(_Timestamp): """ Timestamp.fromtimestamp(ts) - timestamp[, tz] -> tz's local time from POSIX timestamp. + Timestamp[, tz] -> tz's local time from POSIX timestamp. """ return cls(datetime.fromtimestamp(ts)) @@ -934,7 +934,7 @@ class Timestamp(_Timestamp): """ Timestamp.combine(date, time) - date, time -> datetime with same date and time fields. + Date, time -> datetime with same date and time fields. """ return cls(datetime.combine(date, time)) @@ -1153,7 +1153,7 @@ timedelta}, default 'raise' def floor(self, freq, ambiguous='raise', nonexistent='raise'): """ - return a new Timestamp floored to this resolution. + Return a new Timestamp floored to this resolution. Parameters ---------- @@ -1192,7 +1192,7 @@ timedelta}, default 'raise' def ceil(self, freq, ambiguous='raise', nonexistent='raise'): """ - return a new Timestamp ceiled to this resolution. + Return a new Timestamp ceiled to this resolution. Parameters ---------- @@ -1377,7 +1377,7 @@ default 'raise' fold=0, ): """ - implements datetime.replace, handles nanoseconds. + Implements datetime.replace, handles nanoseconds. Parameters ---------- From 42b6d0b27391af02d28062b5ae80067e03424440 Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 1 Nov 2020 11:06:45 -0500 Subject: [PATCH 2/8] CLN: Add SS02 check to code_checks.sh (#25113) --- ci/code_checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 7c48905135f89..9c722789b8011 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -261,7 +261,7 @@ fi ### DOCSTRINGS ### if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then - MSG='Validate docstrings (GL03, GL04, GL05, GL06, GL07, GL09, GL10, SS04, SS05, PR03, PR04, PR05, PR10, EX04, RT01, RT04, RT05, SA02, SA03)' ; echo $MSG + MSG='Validate docstrings (GL03, GL04, GL05, GL06, GL07, GL09, GL10, SS02, SS04, SS05, PR03, PR04, PR05, PR10, EX04, RT01, RT04, RT05, SA02, SA03)' ; echo $MSG $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=GL03,GL04,GL05,GL06,GL07,GL09,GL10,SS04,SS05,PR03,PR04,PR05,PR10,EX04,RT01,RT04,RT05,SA02,SA03 RET=$(($RET + $?)) ; echo $MSG "DONE" From a40f488aa4148e42554e9a5fb3fde1b8647bdc1a Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 1 Nov 2020 11:08:15 -0500 Subject: [PATCH 3/8] Trigger push From 494146753aa28aafdd0edf4b52d62040514a37cd Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 1 Nov 2020 11:18:13 -0500 Subject: [PATCH 4/8] Add whatsnew and ss02 to test --- ci/code_checks.sh | 2 +- doc/source/whatsnew/v1.2.0.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index c9b3111f9780e..1ec3d25137a71 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -239,7 +239,7 @@ fi if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then MSG='Validate docstrings (GL03, GL04, GL05, GL06, GL07, GL09, GL10, SS02, SS04, SS05, PR03, PR04, PR05, PR10, EX04, RT01, RT04, RT05, SA02, SA03)' ; echo $MSG - $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=GL03,GL04,GL05,GL06,GL07,GL09,GL10,SS04,SS05,PR03,PR04,PR05,PR10,EX04,RT01,RT04,RT05,SA02,SA03 + $BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=GL03,GL04,GL05,GL06,GL07,GL09,GL10,SS02,SS04,SS05,PR03,PR04,PR05,PR10,EX04,RT01,RT04,RT05,SA02,SA03 RET=$(($RET + $?)) ; echo $MSG "DONE" MSG='Validate correct capitalization among titles in documentation' ; echo $MSG diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index d07db18ee5df0..46b7730372d89 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -207,6 +207,7 @@ level-by-level basis. Other enhancements ^^^^^^^^^^^^^^^^^^ +- Added SS02 check to ``code_checks.sh``. This will add a check in CI to make sure summary in docstrings begins with capital letter. (:issue:`25113`) - Added ``day_of_week``(compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - Added ``day_of_year`` (compatibility alias ``dayofyear``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - Added :meth:`~DataFrame.set_flags` for setting table-wide flags on a ``Series`` or ``DataFrame`` (:issue:`28394`) From 92419b9433b5a7c02c4d07e5393dbd1cd5f78309 Mon Sep 17 00:00:00 2001 From: amangla Date: Sat, 7 Nov 2020 23:00:34 -0800 Subject: [PATCH 5/8] Revert parameter capitalization, remove whatsnew entry, override strftime --- doc/source/whatsnew/v1.2.0.rst | 1 - pandas/_libs/tslibs/timestamps.pyx | 19 +++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 46b7730372d89..d07db18ee5df0 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -207,7 +207,6 @@ level-by-level basis. Other enhancements ^^^^^^^^^^^^^^^^^^ -- Added SS02 check to ``code_checks.sh``. This will add a check in CI to make sure summary in docstrings begins with capital letter. (:issue:`25113`) - Added ``day_of_week``(compatibility alias ``dayofweek``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - Added ``day_of_year`` (compatibility alias ``dayofyear``) property to ``Timestamp``, ``DatetimeIndex``, ``Period``, ``PeriodIndex`` (:issue:`9605`) - Added :meth:`~DataFrame.set_flags` for setting table-wide flags on a ``Series`` or ``DataFrame`` (:issue:`28394`) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index d14d3b3e5ea37..7b821e4bfaf09 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -912,10 +912,25 @@ class Timestamp(_Timestamp): """ Timestamp.fromtimestamp(ts) - Timestamp[, tz] -> tz's local time from POSIX timestamp. + Transform timestamp[, tz] to tz's local time from POSIX timestamp. """ return cls(datetime.fromtimestamp(ts)) + @classmethod + def strftime(cls, format): + """ + Timestamp.strftime(format) + + Return a string representing the given POSIX timestamp + controlled by an explicit format string. + + Parameters + ---------- + format : str + Format string to convert Timestamp to string. + """ + return cls(datetime.strftime(format)) + # Issue 25016. @classmethod def strptime(cls, date_string, format): @@ -934,7 +949,7 @@ class Timestamp(_Timestamp): """ Timestamp.combine(date, time) - Date, time -> datetime with same date and time fields. + Combine date, time into datetime with same date and time fields. """ return cls(datetime.combine(date, time)) From 51425d7990d227f254dd5e678761c1bcdcc697f1 Mon Sep 17 00:00:00 2001 From: amangla Date: Sat, 7 Nov 2020 23:49:22 -0800 Subject: [PATCH 6/8] Fix override strftime to pass tests --- pandas/_libs/tslibs/timestamps.pyx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 7b821e4bfaf09..9b5cc873c18a5 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -916,8 +916,7 @@ class Timestamp(_Timestamp): """ return cls(datetime.fromtimestamp(ts)) - @classmethod - def strftime(cls, format): + def strftime(self, format): """ Timestamp.strftime(format) @@ -929,7 +928,7 @@ class Timestamp(_Timestamp): format : str Format string to convert Timestamp to string. """ - return cls(datetime.strftime(format)) + return datetime.strftime(self, format) # Issue 25016. @classmethod From 1333f017be8746aec416a93be0ddac1da299ab6e Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 8 Nov 2020 10:32:07 -0800 Subject: [PATCH 7/8] Fix docstrings in NaT definitions --- pandas/_libs/tslibs/nattype.pyx | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index e10ac6a05ead8..96cf9abd1b12c 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -418,7 +418,6 @@ class NaTType(_NaT): utctimetuple = _make_error_func("utctimetuple", datetime) timetz = _make_error_func("timetz", datetime) timetuple = _make_error_func("timetuple", datetime) - strftime = _make_error_func("strftime", datetime) isocalendar = _make_error_func("isocalendar", datetime) dst = _make_error_func("dst", datetime) ctime = _make_error_func("ctime", datetime) @@ -435,6 +434,21 @@ class NaTType(_NaT): # The remaining methods have docstrings copy/pasted from the analogous # Timestamp methods. + strftime = _make_error_func( + "strftime", + """ + Timestamp.strftime(format) + + Return a string representing the given POSIX timestamp + controlled by an explicit format string. + + Parameters + ---------- + format : str + Format string to convert Timestamp to string. + """, + ) + strptime = _make_error_func( "strptime", """ @@ -457,7 +471,7 @@ class NaTType(_NaT): """ Timestamp.fromtimestamp(ts) - timestamp[, tz] -> tz's local time from POSIX timestamp. + Transform timestamp[, tz] to tz's local time from POSIX timestamp. """, ) combine = _make_error_func( @@ -465,7 +479,7 @@ class NaTType(_NaT): """ Timestamp.combine(date, time) - date, time -> datetime with same date and time fields. + Combine date, time into datetime with same date and time fields. """, ) utcnow = _make_error_func( @@ -606,7 +620,7 @@ timedelta}, default 'raise' floor = _make_nat_func( "floor", """ - return a new Timestamp floored to this resolution. + Return a new Timestamp floored to this resolution. Parameters ---------- @@ -645,7 +659,7 @@ timedelta}, default 'raise' ceil = _make_nat_func( "ceil", """ - return a new Timestamp ceiled to this resolution. + Return a new Timestamp ceiled to this resolution. Parameters ---------- @@ -761,7 +775,7 @@ default 'raise' replace = _make_nat_func( "replace", """ - implements datetime.replace, handles nanoseconds. + Implements datetime.replace, handles nanoseconds. Parameters ---------- From 453702f2fd2ba81e52b9fc3e49b7d3a3395d6b2e Mon Sep 17 00:00:00 2001 From: amangla Date: Sun, 8 Nov 2020 21:37:01 -0800 Subject: [PATCH 8/8] Add link to format string documentation --- pandas/_libs/tslibs/nattype.pyx | 2 ++ pandas/_libs/tslibs/timestamps.pyx | 2 ++ 2 files changed, 4 insertions(+) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 96cf9abd1b12c..561143f48e0ec 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -446,6 +446,8 @@ class NaTType(_NaT): ---------- format : str Format string to convert Timestamp to string. + See strftime documentation for more information on the format string: + https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior. """, ) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 9b5cc873c18a5..242eb89d1e723 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -927,6 +927,8 @@ class Timestamp(_Timestamp): ---------- format : str Format string to convert Timestamp to string. + See strftime documentation for more information on the format string: + https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior. """ return datetime.strftime(self, format)