From af104722748b0a4b82f34dcfeba99e0c90054a1e Mon Sep 17 00:00:00 2001 From: Lucas Brown Date: Tue, 3 Dec 2024 10:41:46 -0800 Subject: [PATCH 1/3] DOC: Fix PR02 errors in Timedelta attributes (min, max, resolution) docstrings --- ci/code_checks.sh | 3 --- pandas/_libs/tslibs/timedeltas.pyx | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index dde98a01cc770..8acb346713344 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -75,9 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.RangeIndex.from_range PR01,SA01" \ -i "pandas.Series.dt.unit GL08" \ -i "pandas.Series.pad PR01,SA01" \ - -i "pandas.Timedelta.max PR02" \ - -i "pandas.Timedelta.min PR02" \ - -i "pandas.Timedelta.resolution PR02" \ -i "pandas.Timestamp.max PR02" \ -i "pandas.Timestamp.min PR02" \ -i "pandas.Timestamp.resolution PR02" \ diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index e320aca04683c..b099c400ea0c4 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1894,6 +1894,18 @@ class Timedelta(_Timedelta): Values for construction in compat with datetime.timedelta. Numpy ints and floats will be coerced to python ints and floats. + Attributes + ---------- + min : Timedelta + The minimum representable `Timedelta`, corresponding to the smallest + duration supported. + max : Timedelta + The maximum representable `Timedelta`, corresponding to the largest + duration supported. + resolution : Timedelta + The smallest possible difference between non-equal `Timedelta` objects, + i.e., `Timedelta(nanoseconds=1)`. + See Also -------- Timestamp : Represents a single timestamp in time. @@ -1933,6 +1945,10 @@ class Timedelta(_Timedelta): _req_any_kwargs_new = {"weeks", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"} + min = Timedelta(np.timedelta64(np.iinfo(np.int64).min + 1, 'ns')) + max = Timedelta(np.timedelta64(np.iinfo(np.int64).max, 'ns')) + resolution = Timedelta(1, unit='ns') + def __new__(cls, object value=_no_input, unit=None, **kwargs): if value is _no_input: if not len(kwargs): From 4a3446ecfa5e634114784dce690fa1bb8a57a98e Mon Sep 17 00:00:00 2001 From: Lucas Brown Date: Tue, 3 Dec 2024 11:25:06 -0800 Subject: [PATCH 2/3] Resolve merge conflict by removing Timedelta ignores --- ci/code_checks.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 8acb346713344..c8e7302607591 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -75,9 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.RangeIndex.from_range PR01,SA01" \ -i "pandas.Series.dt.unit GL08" \ -i "pandas.Series.pad PR01,SA01" \ - -i "pandas.Timestamp.max PR02" \ - -i "pandas.Timestamp.min PR02" \ - -i "pandas.Timestamp.resolution PR02" \ -i "pandas.Timestamp.tzinfo GL08" \ -i "pandas.arrays.ArrowExtensionArray PR07,SA01" \ -i "pandas.arrays.IntervalArray.length SA01" \ From fedd2737caa7b75b3ac0d27dcaa857f5ea41651d Mon Sep 17 00:00:00 2001 From: Lucas Brown Date: Tue, 3 Dec 2024 11:37:14 -0800 Subject: [PATCH 3/3] Fix NameError by properly defining Timedelta before using it --- ci/code_checks.sh | 9 --------- pandas/_libs/tslibs/timedeltas.pyx | 6 +++--- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 06e1d6575bcb8..9d6cae7b9bf93 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -73,17 +73,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Period.freq GL08" \ -i "pandas.Period.ordinal GL08" \ -i "pandas.RangeIndex.from_range PR01,SA01" \ -<<<<<<< HEAD -i "pandas.Series.dt.unit GL08" \ -i "pandas.Series.pad PR01,SA01" \ -======= - -i "pandas.Timedelta.max PR02" \ - -i "pandas.Timedelta.min PR02" \ - -i "pandas.Timedelta.resolution PR02" \ - -i "pandas.Timestamp.max PR02" \ - -i "pandas.Timestamp.min PR02" \ - -i "pandas.Timestamp.resolution PR02" \ ->>>>>>> upstream/main -i "pandas.Timestamp.tzinfo GL08" \ -i "pandas.arrays.ArrowExtensionArray PR07,SA01" \ -i "pandas.arrays.IntervalArray.length SA01" \ diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index b099c400ea0c4..b87e67a704888 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1945,9 +1945,9 @@ class Timedelta(_Timedelta): _req_any_kwargs_new = {"weeks", "days", "hours", "minutes", "seconds", "milliseconds", "microseconds", "nanoseconds"} - min = Timedelta(np.timedelta64(np.iinfo(np.int64).min + 1, 'ns')) - max = Timedelta(np.timedelta64(np.iinfo(np.int64).max, 'ns')) - resolution = Timedelta(1, unit='ns') + Timedelta.min = Timedelta(np.timedelta64(np.iinfo(np.int64).min + 1, 'ns')) + Timedelta.max = Timedelta(np.timedelta64(np.iinfo(np.int64).max, 'ns')) + Timedelta.resolution = Timedelta(1, unit='ns') def __new__(cls, object value=_no_input, unit=None, **kwargs): if value is _no_input: