From 49cab81a09554a2f05c99193384968abd9c0276c Mon Sep 17 00:00:00 2001 From: fbourgey Date: Thu, 5 Sep 2024 08:30:01 -0400 Subject: [PATCH 1/7] Add 'See Also' section for Timedelta.to_timedelta64 --- ci/code_checks.sh | 1 - pandas/_libs/tslibs/timedeltas.pyx | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 0714c6f74f0c2..9a3a01a85cc95 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -114,7 +114,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timedelta.min PR02" \ -i "pandas.Timedelta.resolution PR02" \ -i "pandas.Timedelta.to_numpy PR01" \ - -i "pandas.Timedelta.to_timedelta64 SA01" \ -i "pandas.Timedelta.total_seconds SA01" \ -i "pandas.Timedelta.view SA01" \ -i "pandas.TimedeltaIndex.components SA01" \ diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 36be1812b0187..1eec41102f3e1 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1403,6 +1403,14 @@ cdef class _Timedelta(timedelta): """ Return a numpy.timedelta64 object with 'ns' precision. + Returns + ------- + numpy.timedelta64 + + See Also + -------- + Timedelta.to_numpy : Alias method. + Examples -------- >>> td = pd.Timedelta('3D') From cd3fbd6387dd5d48965e92faac8be4b7ec8c4f2e Mon Sep 17 00:00:00 2001 From: fbourgey Date: Thu, 5 Sep 2024 08:35:13 -0400 Subject: [PATCH 2/7] Fix SA01 for Timedelta.total_seconds() --- ci/code_checks.sh | 1 - pandas/_libs/tslibs/timedeltas.pyx | 5 +++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 9a3a01a85cc95..16ed1e982a764 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -114,7 +114,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timedelta.min PR02" \ -i "pandas.Timedelta.resolution PR02" \ -i "pandas.Timedelta.to_numpy PR01" \ - -i "pandas.Timedelta.total_seconds SA01" \ -i "pandas.Timedelta.view SA01" \ -i "pandas.TimedeltaIndex.components SA01" \ -i "pandas.TimedeltaIndex.microseconds SA01" \ diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 1eec41102f3e1..698122dc3dced 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1189,6 +1189,11 @@ cdef class _Timedelta(timedelta): """ Total seconds in the duration. + See Also + -------- + Timedelta.seconds : Returns the seconds component of the timedelta. + Timedelta.microseconds : Returns the microseconds component of the timedelta. + Examples -------- >>> td = pd.Timedelta('1min') From a50aa44c363d62c27102a303bf49b6d25929059c Mon Sep 17 00:00:00 2001 From: fbourgey Date: Thu, 5 Sep 2024 08:39:04 -0400 Subject: [PATCH 3/7] Fix SA01 for Timedelta.view --- ci/code_checks.sh | 1 - pandas/_libs/tslibs/timedeltas.pyx | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 16ed1e982a764..093b2a47a9a7d 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -114,7 +114,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timedelta.min PR02" \ -i "pandas.Timedelta.resolution PR02" \ -i "pandas.Timedelta.to_numpy PR01" \ - -i "pandas.Timedelta.view SA01" \ -i "pandas.TimedeltaIndex.components SA01" \ -i "pandas.TimedeltaIndex.microseconds SA01" \ -i "pandas.TimedeltaIndex.nanoseconds SA01" \ diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 698122dc3dced..765bd054a4f44 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1469,6 +1469,10 @@ cdef class _Timedelta(timedelta): dtype : str or dtype The dtype to view the underlying data as. + See Also + -------- + Timedelta.asm8 : Return a numpy timedelta64 array scalar view. + Examples -------- >>> td = pd.Timedelta('3D') From 86645e294b5c4a095c8dd2dd279c48c8ac4278ee Mon Sep 17 00:00:00 2001 From: fbourgey Date: Fri, 13 Sep 2024 14:01:32 -0400 Subject: [PATCH 4/7] Add space --- pandas/_libs/tslibs/timedeltas.pyx | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 56d26a4badbea..fe4669e0aaca5 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1491,6 +1491,7 @@ cdef class _Timedelta(timedelta): Timedelta.to_numpy : Converts the Timedelta to a NumPy timedelta64. Timedelta.total_seconds : Returns the total duration of the Timedelta object in seconds. + Examples -------- >>> td = pd.Timedelta('3D') From 9d0965805daa2dbd02eaa1878858cfb0eb97df02 Mon Sep 17 00:00:00 2001 From: fbourgey Date: Fri, 13 Sep 2024 15:23:55 -0400 Subject: [PATCH 5/7] Fix test_nat_doc_strings --- pandas/tests/scalar/test_nat.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index b20df43dd49a6..1d3595f5de84b 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -326,6 +326,9 @@ def test_nat_doc_strings(compare): "Ignore differences with Timestamp.isoformat() as they're intentional" ) + if klass == Timedelta and method == "total_seconds": + pytest.skip("Ignore difference") + if method == "to_numpy": # GH#44460 can return either dt64 or td64 depending on dtype, # different docstring is intentional From 1c0a1185f7e8e28e51fd38e03b85b8c1317ac7b3 Mon Sep 17 00:00:00 2001 From: fbourgey Date: Wed, 18 Sep 2024 11:12:30 -0400 Subject: [PATCH 6/7] Revert "Fix test_nat_doc_strings" This reverts commit 9d0965805daa2dbd02eaa1878858cfb0eb97df02. --- pandas/tests/scalar/test_nat.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index 1d3595f5de84b..b20df43dd49a6 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -326,9 +326,6 @@ def test_nat_doc_strings(compare): "Ignore differences with Timestamp.isoformat() as they're intentional" ) - if klass == Timedelta and method == "total_seconds": - pytest.skip("Ignore difference") - if method == "to_numpy": # GH#44460 can return either dt64 or td64 depending on dtype, # different docstring is intentional From 4e6e36ba1fe70accdf7ae723fd709a5330f4397f Mon Sep 17 00:00:00 2001 From: fbourgey Date: Wed, 18 Sep 2024 11:33:03 -0400 Subject: [PATCH 7/7] Match doc of total_seconds method in nattype.pyx --- pandas/_libs/tslibs/nattype.pyx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index 60afc1acdc297..ed503c3ebf691 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -493,6 +493,11 @@ class NaTType(_NaT): """ Total seconds in the duration. + See Also + -------- + Timedelta.seconds : Returns the seconds component of the timedelta. + Timedelta.microseconds : Returns the microseconds component of the timedelta. + Examples -------- >>> td = pd.Timedelta('1min')