From d3eda3c111f93c2bbbc9aeb7bd77c280c298ee60 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Sun, 11 Aug 2024 17:11:57 +0100 Subject: [PATCH 01/13] Changes to fix docstring issue with pandas.Timestamp.hour --- ci/code_checks.sh | 1 - pandas/_libs/tslibs/timestamps.pyx | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index c53265e126bf0..e10607909ea12 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -211,7 +211,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.fold GL08" \ -i "pandas.Timestamp.fromordinal SA01" \ -i "pandas.Timestamp.fromtimestamp PR01,SA01" \ - -i "pandas.Timestamp.hour GL08" \ -i "pandas.Timestamp.max PR02" \ -i "pandas.Timestamp.microsecond GL08" \ -i "pandas.Timestamp.min PR02" \ diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 369184d9df40c..6fca0e63a4a6f 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -590,6 +590,36 @@ cdef class _Timestamp(ABCTimestamp): field, freq_name, month_kw, self._creso) return out[0] + def hour(self) -> int: + """ + Returns the hour component of the timestamp. + + Extended Summary + -------- + The hour is represented as an integer ranging from 0 to 23, where 0 corresponds + to midnight (00:00) and 23 corresponds to the last hour of the day (23:00). + + Returns + -------- + int + The hour component of the timestamp as an integer between 0 and 23. + + See Also + -------- + Timestamp.minute : Similar property indicating the minute of the timestamp. + + Examples + -------- + >>> ts = pd.Timestamp('2020-03-14T12:32:52.192548651') + >>> ts.hour() + 12 + + >>> ts = pd.Timestamp('2020-03-14T22:43:12.192547851') + >>> ts.hour() + 22 + """ + return self.hour + @property def is_month_start(self) -> bool: """ From ede2e2d142a284e98fdfb2dea8d5b8206ac6a8d1 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 23 Aug 2024 14:42:37 +0100 Subject: [PATCH 02/13] fix ci --- pandas/_libs/tslibs/timestamps.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index fa2b9f0d30355..4ff92e2b48e52 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -616,13 +616,11 @@ cdef class _Timestamp(ABCTimestamp): """ Returns the hour component of the timestamp. - Extended Summary - -------- The hour is represented as an integer ranging from 0 to 23, where 0 corresponds to midnight (00:00) and 23 corresponds to the last hour of the day (23:00). Returns - -------- + ------- int The hour component of the timestamp as an integer between 0 and 23. From 887f5fe53d60626f50811f60e5c5d89690d3b703 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 23 Aug 2024 23:25:58 +0100 Subject: [PATCH 03/13] changes to add min,max and microsec --- ci/code_checks.sh | 3 -- pandas/_libs/tslibs/timestamps.pyx | 76 ++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index e12e96bfadd15..abe5a8d4c2031 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -181,9 +181,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \ -i "pandas.Timestamp.day GL08" \ -i "pandas.Timestamp.fold GL08" \ - -i "pandas.Timestamp.max PR02" \ - -i "pandas.Timestamp.microsecond GL08" \ - -i "pandas.Timestamp.min PR02" \ -i "pandas.Timestamp.minute GL08" \ -i "pandas.Timestamp.month GL08" \ -i "pandas.Timestamp.nanosecond GL08" \ diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 4ff92e2b48e52..70608fcc01e11 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -612,6 +612,82 @@ cdef class _Timestamp(ABCTimestamp): field, freq_name, month_kw, self._creso) return out[0] + @property + def microsecond(self) -> int: + """ + Return the microsecond component of the Timestamp. + + The microsecond component represents the number of microseconds + (0 to 999,999) of the Timestamp. + + Returns + ------- + int + Microsecond component of the Timestamp, ranging from 0 to 999,999. + + See Also + -------- + Timestamp.second : Return the second component of the Timestamp. + Timestamp.minute : Return the minute component of the Timestamp. + + Examples + -------- + >>> ts = pd.Timestamp('2024-08-23 14:30:15.123456') + >>> ts.microsecond + 123456 + """ + return self.microsecond + + def max(self): + """ + A constant that represents the maximum valid date and time value for a + pandas Timestamp object. + + This property returns the highest datetime value that can be represented + by a pandas.Timestamp object, which is equivalent to + pd.Timestamp('2262-04-11 23:47:16.854775807'). + + Returns + ------- + Timestamp + The maximum valid datetime value for a Timestamp object. + + See Also + -------- + Timestamp.min : Return the minimum valid date and time value for + pandas Timestamp object. + + Examples + -------- + >>> pd.Timestamp.max + Timestamp('2262-04-11 23:47:16.854775807') + """ + return max + + def min(self): + """ + Return the minimum representable Timestamp. + + This property returns the earliest datetime value that can be represented + by a pandas.Timestamp object, which is equivalent to + pd.Timestamp('1677-09-21 00:12:43.145224193'). + + Returns + ------- + Timestamp + The earliest representable Timestamp. + + See Also + -------- + Timestamp.max : Return the maximum representable Timestamp. + + Examples + -------- + >>> pd.Timestamp.min + Timestamp('1677-09-21 00:12:43.145224193') + """ + return min + def hour(self) -> int: """ Returns the hour component of the timestamp. From 224e1ba3a8721d6dbf6ae2477fcfa359d4963e61 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 23 Aug 2024 23:37:49 +0100 Subject: [PATCH 04/13] fix ci --- pandas/_libs/tslibs/timestamps.pyx | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 70608fcc01e11..55f35e54dbb71 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -632,16 +632,15 @@ cdef class _Timestamp(ABCTimestamp): Examples -------- - >>> ts = pd.Timestamp('2024-08-23 14:30:15.123456') - >>> ts.microsecond - 123456 + >>> ts = pd.Timestamp('2024-08-23 14:30:15.123456') + >>> ts.microsecond + 123456 """ return self.microsecond def max(self): """ - A constant that represents the maximum valid date and time value for a - pandas Timestamp object. + A constant that represents the maximum valid date and time value. This property returns the highest datetime value that can be represented by a pandas.Timestamp object, which is equivalent to @@ -654,13 +653,12 @@ cdef class _Timestamp(ABCTimestamp): See Also -------- - Timestamp.min : Return the minimum valid date and time value for - pandas Timestamp object. + Timestamp.min : Return the minimum valid date and time value for Timestamp. Examples -------- - >>> pd.Timestamp.max - Timestamp('2262-04-11 23:47:16.854775807') + >>> pd.Timestamp.max + Timestamp('2262-04-11 23:47:16.854775807') """ return max @@ -706,13 +704,13 @@ cdef class _Timestamp(ABCTimestamp): Examples -------- - >>> ts = pd.Timestamp('2020-03-14T12:32:52.192548651') - >>> ts.hour() - 12 + >>> ts = pd.Timestamp('2020-03-14T12:32:52.192548651') + >>> ts.hour() + 12 - >>> ts = pd.Timestamp('2020-03-14T22:43:12.192547851') - >>> ts.hour() - 22 + >>> ts = pd.Timestamp('2020-03-14T22:43:12.192547851') + >>> ts.hour() + 22 """ return self.hour From 7ac2ecb5448b7dc3dcce56f1ca93971396496f69 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 30 Aug 2024 20:05:11 +0100 Subject: [PATCH 05/13] fix merge conflict --- ci/code_checks.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index e7b6e51170370..a6a697da5235a 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -133,8 +133,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.fold GL08" \ -i "pandas.Timestamp.minute GL08" \ -i "pandas.Timestamp.month GL08" \ - -i "pandas.Timestamp.max PR02" \ - -i "pandas.Timestamp.min PR02" \ -i "pandas.Timestamp.nanosecond GL08" \ -i "pandas.Timestamp.resolution PR02" \ -i "pandas.Timestamp.tzinfo GL08" \ From 18a1adcfb0922b7d0f520961dd5cc239619d2f39 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 30 Aug 2024 20:06:13 +0100 Subject: [PATCH 06/13] fix merge conflict --- ci/code_checks.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index a6a697da5235a..110c29737f1ae 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -129,10 +129,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.TimedeltaIndex.nanoseconds SA01" \ -i "pandas.TimedeltaIndex.seconds SA01" \ -i "pandas.TimedeltaIndex.to_pytimedelta RT03,SA01" \ - -i "pandas.Timestamp.day GL08" \ - -i "pandas.Timestamp.fold GL08" \ - -i "pandas.Timestamp.minute GL08" \ - -i "pandas.Timestamp.month GL08" \ -i "pandas.Timestamp.nanosecond GL08" \ -i "pandas.Timestamp.resolution PR02" \ -i "pandas.Timestamp.tzinfo GL08" \ From 646dc9f02dc2db2b7e1834e5955ca6ef7dfbe626 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 30 Aug 2024 20:20:25 +0100 Subject: [PATCH 07/13] remove hour and microsecond --- pandas/_libs/tslibs/timestamps.pyx | 54 +----------------------------- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 75d98f41ac57c..d9501db035af6 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -613,31 +613,6 @@ cdef class _Timestamp(ABCTimestamp): return out[0] @property - def microsecond(self) -> int: - """ - Return the microsecond component of the Timestamp. - - The microsecond component represents the number of microseconds - (0 to 999,999) of the Timestamp. - - Returns - ------- - int - Microsecond component of the Timestamp, ranging from 0 to 999,999. - - See Also - -------- - Timestamp.second : Return the second component of the Timestamp. - Timestamp.minute : Return the minute component of the Timestamp. - - Examples - -------- - >>> ts = pd.Timestamp('2024-08-23 14:30:15.123456') - >>> ts.microsecond - 123456 - """ - return self.microsecond - def max(self): """ A constant that represents the maximum valid date and time value. @@ -662,6 +637,7 @@ cdef class _Timestamp(ABCTimestamp): """ return max + @property def min(self): """ Return the minimum representable Timestamp. @@ -686,34 +662,6 @@ cdef class _Timestamp(ABCTimestamp): """ return min - def hour(self) -> int: - """ - Returns the hour component of the timestamp. - - The hour is represented as an integer ranging from 0 to 23, where 0 corresponds - to midnight (00:00) and 23 corresponds to the last hour of the day (23:00). - - Returns - ------- - int - The hour component of the timestamp as an integer between 0 and 23. - - See Also - -------- - Timestamp.minute : Similar property indicating the minute of the timestamp. - - Examples - -------- - >>> ts = pd.Timestamp('2020-03-14T12:32:52.192548651') - >>> ts.hour() - 12 - - >>> ts = pd.Timestamp('2020-03-14T22:43:12.192547851') - >>> ts.hour() - 22 - """ - return self.hour - @property def is_month_start(self) -> bool: """ From 89285c2270a54f8af21a7083dc083a81ed849787 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 30 Aug 2024 20:43:39 +0100 Subject: [PATCH 08/13] remove hour and microsecond --- pandas/_libs/tslibs/timestamps.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index d9501db035af6..d0aa320aaa09b 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -635,7 +635,7 @@ cdef class _Timestamp(ABCTimestamp): >>> pd.Timestamp.max Timestamp('2262-04-11 23:47:16.854775807') """ - return max + return self.max @property def min(self): @@ -660,7 +660,7 @@ cdef class _Timestamp(ABCTimestamp): >>> pd.Timestamp.min Timestamp('1677-09-21 00:12:43.145224193') """ - return min + return self.min @property def is_month_start(self) -> bool: From 90471085b719461dbcbbb9c4b68c4c7e77c482c0 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 30 Aug 2024 21:28:53 +0100 Subject: [PATCH 09/13] fix CI --- pandas/_libs/tslibs/timestamps.pyx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index d0aa320aaa09b..b235a9f02d682 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -612,8 +612,7 @@ cdef class _Timestamp(ABCTimestamp): field, freq_name, month_kw, self._creso) return out[0] - @property - def max(self): + def max(self) -> "Timestamp": """ A constant that represents the maximum valid date and time value. @@ -635,10 +634,9 @@ cdef class _Timestamp(ABCTimestamp): >>> pd.Timestamp.max Timestamp('2262-04-11 23:47:16.854775807') """ - return self.max + return max - @property - def min(self): + def min(self) -> "Timestamp": """ Return the minimum representable Timestamp. @@ -660,7 +658,7 @@ cdef class _Timestamp(ABCTimestamp): >>> pd.Timestamp.min Timestamp('1677-09-21 00:12:43.145224193') """ - return self.min + return min @property def is_month_start(self) -> bool: From d8ad329ba90c67aef4271ea4811f2c8fe2edfa34 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 30 Aug 2024 21:49:40 +0100 Subject: [PATCH 10/13] remove return statement --- pandas/_libs/tslibs/timestamps.pyx | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index b235a9f02d682..1ff8fea4358f9 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -634,7 +634,6 @@ cdef class _Timestamp(ABCTimestamp): >>> pd.Timestamp.max Timestamp('2262-04-11 23:47:16.854775807') """ - return max def min(self) -> "Timestamp": """ @@ -658,7 +657,6 @@ cdef class _Timestamp(ABCTimestamp): >>> pd.Timestamp.min Timestamp('1677-09-21 00:12:43.145224193') """ - return min @property def is_month_start(self) -> bool: From b72042e87be460affb3d9600340e968d253aeca4 Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Fri, 6 Sep 2024 23:04:21 +0100 Subject: [PATCH 11/13] changes to test --- pandas/_libs/tslibs/timestamps.pyx | 46 ------------------------------ 1 file changed, 46 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 50b7ef791445c..34c84d396ad64 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -633,52 +633,6 @@ cdef class _Timestamp(ABCTimestamp): field, freq_name, month_kw, self._creso) return out[0] - def max(self) -> "Timestamp": - """ - A constant that represents the maximum valid date and time value. - - This property returns the highest datetime value that can be represented - by a pandas.Timestamp object, which is equivalent to - pd.Timestamp('2262-04-11 23:47:16.854775807'). - - Returns - ------- - Timestamp - The maximum valid datetime value for a Timestamp object. - - See Also - -------- - Timestamp.min : Return the minimum valid date and time value for Timestamp. - - Examples - -------- - >>> pd.Timestamp.max - Timestamp('2262-04-11 23:47:16.854775807') - """ - - def min(self) -> "Timestamp": - """ - Return the minimum representable Timestamp. - - This property returns the earliest datetime value that can be represented - by a pandas.Timestamp object, which is equivalent to - pd.Timestamp('1677-09-21 00:12:43.145224193'). - - Returns - ------- - Timestamp - The earliest representable Timestamp. - - See Also - -------- - Timestamp.max : Return the maximum representable Timestamp. - - Examples - -------- - >>> pd.Timestamp.min - Timestamp('1677-09-21 00:12:43.145224193') - """ - @property def is_month_start(self) -> bool: """ From e16a327b8a1eeac3f82d13e548f05c96db7cf19e Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Sat, 7 Sep 2024 13:51:32 +0100 Subject: [PATCH 12/13] min and max revert --- pandas/_libs/tslibs/timestamps.pyx | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 34c84d396ad64..50b7ef791445c 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -633,6 +633,52 @@ cdef class _Timestamp(ABCTimestamp): field, freq_name, month_kw, self._creso) return out[0] + def max(self) -> "Timestamp": + """ + A constant that represents the maximum valid date and time value. + + This property returns the highest datetime value that can be represented + by a pandas.Timestamp object, which is equivalent to + pd.Timestamp('2262-04-11 23:47:16.854775807'). + + Returns + ------- + Timestamp + The maximum valid datetime value for a Timestamp object. + + See Also + -------- + Timestamp.min : Return the minimum valid date and time value for Timestamp. + + Examples + -------- + >>> pd.Timestamp.max + Timestamp('2262-04-11 23:47:16.854775807') + """ + + def min(self) -> "Timestamp": + """ + Return the minimum representable Timestamp. + + This property returns the earliest datetime value that can be represented + by a pandas.Timestamp object, which is equivalent to + pd.Timestamp('1677-09-21 00:12:43.145224193'). + + Returns + ------- + Timestamp + The earliest representable Timestamp. + + See Also + -------- + Timestamp.max : Return the maximum representable Timestamp. + + Examples + -------- + >>> pd.Timestamp.min + Timestamp('1677-09-21 00:12:43.145224193') + """ + @property def is_month_start(self) -> bool: """ From be7526adc7da6b0c06293a81a013215d7184473b Mon Sep 17 00:00:00 2001 From: Navaneettha Sundararaj Date: Sat, 7 Sep 2024 14:35:46 +0100 Subject: [PATCH 13/13] check for attribute --- pandas/_libs/tslibs/timestamps.pyx | 59 +++++++----------------------- 1 file changed, 13 insertions(+), 46 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 50b7ef791445c..eb2ae13bdccf0 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -633,52 +633,6 @@ cdef class _Timestamp(ABCTimestamp): field, freq_name, month_kw, self._creso) return out[0] - def max(self) -> "Timestamp": - """ - A constant that represents the maximum valid date and time value. - - This property returns the highest datetime value that can be represented - by a pandas.Timestamp object, which is equivalent to - pd.Timestamp('2262-04-11 23:47:16.854775807'). - - Returns - ------- - Timestamp - The maximum valid datetime value for a Timestamp object. - - See Also - -------- - Timestamp.min : Return the minimum valid date and time value for Timestamp. - - Examples - -------- - >>> pd.Timestamp.max - Timestamp('2262-04-11 23:47:16.854775807') - """ - - def min(self) -> "Timestamp": - """ - Return the minimum representable Timestamp. - - This property returns the earliest datetime value that can be represented - by a pandas.Timestamp object, which is equivalent to - pd.Timestamp('1677-09-21 00:12:43.145224193'). - - Returns - ------- - Timestamp - The earliest representable Timestamp. - - See Also - -------- - Timestamp.max : Return the maximum representable Timestamp. - - Examples - -------- - >>> pd.Timestamp.min - Timestamp('1677-09-21 00:12:43.145224193') - """ - @property def is_month_start(self) -> bool: """ @@ -1741,6 +1695,19 @@ class Timestamp(_Timestamp): datetime-like corresponds to the first (0) or the second time (1) the wall clock hits the ambiguous time. + Attributes + ---------- + max : Timestamp + A constant that represents the maximum valid date and time value. + This property returns the highest datetime value that can be represented + by a pandas.Timestamp object, which is equivalent to + pd.Timestamp('2262-04-11 23:47:16.854775807'). + min : Timestamp + A constant that represents the minimum valid date and time value. + This property returns the earliest datetime value that can be represented + by a pandas.Timestamp object, which is equivalent to + pd.Timestamp('1677-09-21 00:12:43.145224193'). + See Also -------- Timedelta : Represents a duration, the difference between two dates or times.