diff --git a/ci/code_checks.sh b/ci/code_checks.sh index b5d63e259456b..1ec3d25137a71 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -238,8 +238,8 @@ 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 - $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 + 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,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/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index e10ac6a05ead8..561143f48e0ec 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,23 @@ 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. + See strftime documentation for more information on the format string: + https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior. + """, + ) + strptime = _make_error_func( "strptime", """ @@ -457,7 +473,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 +481,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 +622,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 +661,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 +777,7 @@ default 'raise' replace = _make_nat_func( "replace", """ - implements datetime.replace, handles nanoseconds. + Implements datetime.replace, handles nanoseconds. Parameters ---------- diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index b3ae69d7a3237..242eb89d1e723 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -912,10 +912,26 @@ 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)) + def strftime(self, 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. + 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) + # Issue 25016. @classmethod def strptime(cls, date_string, format): @@ -934,7 +950,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)) @@ -1153,7 +1169,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 +1208,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 +1393,7 @@ default 'raise' fold=None, ): """ - implements datetime.replace, handles nanoseconds. + Implements datetime.replace, handles nanoseconds. Parameters ----------