From 242b34a48bfd0b5b3cc60113ef96b49c0e789c0c Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Tue, 13 Aug 2024 17:25:24 -0400 Subject: [PATCH 1/9] strptime --- pandas/_libs/tslibs/nattype.pyx | 20 ++++++++++++++++++-- pandas/_libs/tslibs/timestamps.pyx | 20 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 547f95badab53..cdd0f5f72fc69 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -786,9 +786,25 @@ class NaTType(_NaT): strptime = _make_error_func( "strptime", """ - Timestamp.strptime(string, format) + Convert string argument to datetime. - Function is not implemented. Use pd.to_datetime(). + This function is not implemented; calling it will raise NotImplementedError. + Use pd.to_datetime() insteads. + + Parameters + ---------- + date_string : str + String to convert to a datetime. + format : str, default None + The format string to parse time, e.g. "%d/%m/%Y". + + See Also + -------- + pd.to_datetime : Convert argument to datetime. + datetime.datetime.strftime : + Return a string representing the date and time, controlled by an + explicit format string. + Timestamp.isoformat : Return the time formatted according to ISO 8601. Examples -------- diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 47e5af14460a8..810a301cdc356 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1940,9 +1940,25 @@ class Timestamp(_Timestamp): @classmethod def strptime(cls, date_string, format): """ - Timestamp.strptime(string, format) + Convert string argument to datetime. - Function is not implemented. Use pd.to_datetime(). + This function is not implemented; calling it will raise NotImplementedError. + Use pd.to_datetime() insteads. + + Parameters + ---------- + date_string : str + String to convert to a datetime. + format : str, default None + The format string to parse time, e.g. "%d/%m/%Y". + + See Also + -------- + pd.to_datetime : Convert argument to datetime. + datetime.datetime.strftime : + Return a string representing the date and time, controlled by an + explicit format string. + Timestamp.isoformat : Return the time formatted according to ISO 8601. Examples -------- From 4d24eea50766d4e3f9115920d748825e90e72f3d Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Thu, 15 Aug 2024 16:53:56 -0400 Subject: [PATCH 2/9] strptime + timestamp --- pandas/_libs/tslibs/nattype.pyx | 22 +++++++++++++++++----- pandas/_libs/tslibs/timestamps.pyx | 22 +++++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index cdd0f5f72fc69..cc8c77336b156 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -788,8 +788,8 @@ class NaTType(_NaT): """ Convert string argument to datetime. - This function is not implemented; calling it will raise NotImplementedError. - Use pd.to_datetime() insteads. + This method is not implemented; calling it will raise NotImplementedError. + Use pd.to_datetime() instead. Parameters ---------- @@ -801,9 +801,11 @@ class NaTType(_NaT): See Also -------- pd.to_datetime : Convert argument to datetime. - datetime.datetime.strftime : - Return a string representing the date and time, controlled by an - explicit format string. + datetime.datetime.strptime : Return a datetime corresponding to a string + representing a date and time, parsed according to a separate + format string. + datetime.datetime.strftime : Return a string representing the date and + time, controlled by an explicit format string. Timestamp.isoformat : Return the time formatted according to ISO 8601. Examples @@ -907,6 +909,16 @@ class NaTType(_NaT): """ Return POSIX timestamp as float. + This method returns the POSIX timestamp corresponding to the + pd.Timestamp instance. The result does not match the standard + library's datetime.datetime.timestamp() for naive timestamps. + + See Also + -------- + datetime.datetime.timestamp : Return POSIX timestamp + corresponding to the datetime instance. + Timestamp.tz_localize : Localize the pd.Timestamp to a timezone. + Examples -------- >>> ts = pd.Timestamp('2020-03-14T15:32:52.192548') diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 810a301cdc356..085787f360c70 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1212,6 +1212,16 @@ cdef class _Timestamp(ABCTimestamp): """ Return POSIX timestamp as float. + This method returns the POSIX timestamp corresponding to the + pd.Timestamp instance. The result does not match the standard + library's datetime.datetime.timestamp() for naive timestamps. + + See Also + -------- + datetime.datetime.timestamp : Return POSIX timestamp + corresponding to the datetime instance. + Timestamp.tz_localize : Localize the pd.Timestamp to a timezone. + Examples -------- >>> ts = pd.Timestamp('2020-03-14T15:32:52.192548') @@ -1942,8 +1952,8 @@ class Timestamp(_Timestamp): """ Convert string argument to datetime. - This function is not implemented; calling it will raise NotImplementedError. - Use pd.to_datetime() insteads. + This method is not implemented; calling it will raise NotImplementedError. + Use pd.to_datetime() instead. Parameters ---------- @@ -1955,9 +1965,11 @@ class Timestamp(_Timestamp): See Also -------- pd.to_datetime : Convert argument to datetime. - datetime.datetime.strftime : - Return a string representing the date and time, controlled by an - explicit format string. + datetime.datetime.strptime : Return a datetime corresponding to a string + representing a date and time, parsed according to a separate + format string. + datetime.datetime.strftime : Return a string representing the date and + time, controlled by an explicit format string. Timestamp.isoformat : Return the time formatted according to ISO 8601. Examples From 38736f17f6501aa7447f65de1ee852b93e4fa4b5 Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Mon, 19 Aug 2024 16:42:45 -0400 Subject: [PATCH 3/9] timetuple --- pandas/_libs/tslibs/nattype.pyx | 15 +++++++++++++++ pandas/_libs/tslibs/timestamps.pyx | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index cc8c77336b156..836bda81f4c15 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -704,6 +704,21 @@ class NaTType(_NaT): """ Return time tuple, compatible with time.localtime(). + This method extracts the year, month, day, hour, and other + standard information from the pd.Timestamp object and + returns a time.struct_time object. These attributes are + accessible by both name and index in the return value. + + See Also + -------- + time.struct_time : Class with named tuple interface, + with attributes for the standard parts of a timestamp + (year, month, day, hour, and so on). + datetime.datetime.timetuple : Return a time.struct_time + object corresponding to the datetime object. + time.localtime : Convert a float-type POSIX timestamp + to time.struct_time expressed using the local timezone. + Examples -------- >>> ts = pd.Timestamp('2023-01-01 10:00:00') diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 085787f360c70..29b2b55b2d7bc 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1889,6 +1889,21 @@ class Timestamp(_Timestamp): """ Return time tuple, compatible with time.localtime(). + This method extracts the year, month, day, hour, and other + standard information from the pd.Timestamp object and + returns a time.struct_time object. These attributes are + accessible by both name and index in the return value. + + See Also + -------- + time.struct_time : Class with named tuple interface, + with attributes for the standard parts of a timestamp + (year, month, day, hour, and so on). + datetime.datetime.timetuple : Return a time.struct_time + object corresponding to the datetime object. + time.localtime : Convert a float-type POSIX timestamp + to time.struct_time expressed using the local timezone. + Examples -------- >>> ts = pd.Timestamp('2023-01-01 10:00:00') From acd7eeb469bdff3d5662cd1ea15a3ce8acd5088f Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Mon, 19 Aug 2024 17:05:47 -0400 Subject: [PATCH 4/9] timetz --- pandas/_libs/tslibs/nattype.pyx | 14 ++++++++++++++ pandas/_libs/tslibs/timestamps.pyx | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 836bda81f4c15..40d207779c915 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -734,6 +734,20 @@ class NaTType(_NaT): """ Return time object with same time and tzinfo. + This method returns a datetime.time object with + the time and tzinfo corresponding to the pd.Timestamp + object, ignoring any information about the day/date. + + See Also + -------- + datetime.datetime.timetz : Return datetime.time object with the + same hour, minute, second, microsecond, fold, and + tzinfo attributes as the datetime object. + datetime.time : Class to represent the time of day, independent + of any particular day. + datetime.datetime.tzinfo : Attribute of datetime.datetime objects + representing the timezone of the datetime object. + Examples -------- >>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels') diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 29b2b55b2d7bc..8c259a40d8a0a 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1928,6 +1928,20 @@ class Timestamp(_Timestamp): """ Return time object with same time and tzinfo. + This method returns a datetime.time object with + the time and tzinfo corresponding to the pd.Timestamp + object, ignoring any information about the day/date. + + See Also + -------- + datetime.datetime.timetz : Return datetime.time object with the + same hour, minute, second, microsecond, fold, and + tzinfo attributes as the datetime object. + datetime.time : Class to represent the time of day, independent + of any particular day. + datetime.datetime.tzinfo : Attribute of datetime.datetime objects + representing the timezone of the datetime object. + Examples -------- >>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels') From 1a6405c2cf3e4d31e9aa8b44e82c447c02b82512 Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Mon, 19 Aug 2024 17:26:09 -0400 Subject: [PATCH 5/9] to_datetime64 --- pandas/_libs/tslibs/nattype.pyx | 12 +++++++++++- pandas/_libs/tslibs/timestamps.pyx | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 40d207779c915..fa79b860b3414 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -229,7 +229,17 @@ cdef class _NaT(datetime): def to_datetime64(self) -> np.datetime64: """ - Return a numpy.datetime64 object with same precision. + Return a NumPy datetime64 object with same precision. + + This method returns a numpy.datetime64 object with the same + date and time information and precision as the pd.Timestamp object. + + See Also + -------- + numpy.datetime64 : Class to represent dates and times with high precision. + Timestamp.to_numpy : Alias for this method. + Timestamp.asm8 : Alias for this method. + pd.to_datetime : Convert argument to datetime. Examples -------- diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 8c259a40d8a0a..138c940fbff87 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1285,7 +1285,17 @@ cdef class _Timestamp(ABCTimestamp): cpdef to_datetime64(self): """ - Return a numpy.datetime64 object with same precision. + Return a NumPy datetime64 object with same precision. + + This method returns a numpy.datetime64 object with the same + date and time information and precision as the pd.Timestamp object. + + See Also + -------- + numpy.datetime64 : Class to represent dates and times with high precision. + Timestamp.to_numpy : Alias for this method. + Timestamp.asm8 : Alias for this method. + pd.to_datetime : Convert argument to datetime. Examples -------- From b1cec4070e383715e1bfe1b33163d03a8ca51d6e Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Tue, 20 Aug 2024 16:27:32 -0400 Subject: [PATCH 6/9] to_julian_date --- pandas/_libs/tslibs/timestamps.pyx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 138c940fbff87..8bb37fa8916c5 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -2892,7 +2892,14 @@ default 'raise' """ Convert TimeStamp to a Julian Date. - 0 Julian date is noon January 1, 4713 BC. + This method returns the number of days as a float since + 0 Julian date, which is noon January 1, 4713 BC. + + See Also + -------- + pd.to_datetime : Convert argument to datetime. + Timestamp.to_datetime64 : Convert pd.Timestamp instance + to NumPy datetime64 object. Examples -------- From ad4fac4db6269e7bb80f61305bab29df27fc7d0b Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Tue, 20 Aug 2024 16:34:37 -0400 Subject: [PATCH 7/9] timetz --- pandas/_libs/tslibs/nattype.pyx | 3 +-- pandas/_libs/tslibs/timestamps.pyx | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index fa79b860b3414..fbdc0323fc0a2 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -751,8 +751,7 @@ class NaTType(_NaT): See Also -------- datetime.datetime.timetz : Return datetime.time object with the - same hour, minute, second, microsecond, fold, and - tzinfo attributes as the datetime object. + same time attributes as the datetime object. datetime.time : Class to represent the time of day, independent of any particular day. datetime.datetime.tzinfo : Attribute of datetime.datetime objects diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 8bb37fa8916c5..dc6dbd740d5ee 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1945,8 +1945,7 @@ class Timestamp(_Timestamp): See Also -------- datetime.datetime.timetz : Return datetime.time object with the - same hour, minute, second, microsecond, fold, and - tzinfo attributes as the datetime object. + same time attributes as the datetime object. datetime.time : Class to represent the time of day, independent of any particular day. datetime.datetime.tzinfo : Attribute of datetime.datetime objects From 417e139590707d184da806071aa0d64b2ea6e043 Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Tue, 20 Aug 2024 16:45:56 -0400 Subject: [PATCH 8/9] code_checks --- ci/code_checks.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index ac163a3408c25..f1aeda9cbdc9d 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -191,9 +191,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.nanosecond GL08" \ -i "pandas.Timestamp.resolution PR02" \ -i "pandas.Timestamp.second GL08" \ - -i "pandas.Timestamp.strptime PR01,SA01" \ - -i "pandas.Timestamp.timetz SA01" \ - -i "pandas.Timestamp.to_datetime64 SA01" \ -i "pandas.Timestamp.tzinfo GL08" \ -i "pandas.Timestamp.value GL08" \ -i "pandas.Timestamp.year GL08" \ From 69e887fd9182a0fbbd62500a6e947ddfd6cdd3a3 Mon Sep 17 00:00:00 2001 From: "Mien (Josephine) Nguyen" Date: Tue, 20 Aug 2024 17:02:10 -0400 Subject: [PATCH 9/9] duplicate see also --- pandas/_libs/tslibs/timestamps.pyx | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 10acd03614777..3268207b667f2 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -3117,12 +3117,6 @@ default 'raise' This method returns the number of days as a float since 0 Julian date, which is noon January 1, 4713 BC. - See Also - -------- - pd.to_datetime : Convert argument to datetime. - Timestamp.to_datetime64 : Convert pd.Timestamp instance - to NumPy datetime64 object. - See Also -------- Timestamp.toordinal : Return proleptic Gregorian ordinal.