From 16f7e912cae04c4adfa0482679dc6bd848a61c91 Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Wed, 6 Mar 2024 23:00:57 +0530 Subject: [PATCH 1/9] fix GL08 error and write docstring for pandas.Series.dt --- pandas/core/indexes/accessors.py | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 5881f5e040370..9aa11e492f10c 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -571,6 +571,57 @@ class PeriodProperties(Properties): class CombinedDatetimelikeProperties( DatetimeProperties, TimedeltaProperties, PeriodProperties ): + """ + Combined datetime-like properties for a pandas Series. + Not meant to be instantiated directly. Instead, used to determine the appropriate + parent class (ArrowTemporalProperties, DatetimeProperties,TimedeltaProperties, + or PeriodProperties) based on the dtype of the provided pandas Series. + + Raises + ------ + TypeError + If object is not a pandas Series. + + Returns + ------- + Instance of the appropriate subclass (ArrowTemporalProperties, + DatetimeProperties, TimedeltaProperties, or PeriodProperties) + + See Also + -------- + pandas.Series.dt : Accessor object for datetimelike properties of the Series values. + + Examples + -------- + >>> dates = pd.Series( + ... ["2024-01-01", "2024-01-15", "2024-02-5"], dtype="datetime64[ns]" + ... ) + >>> dates.dt.day + 0 1 + 1 15 + 2 5 + dtype: int32 + >>> dates.dt.month + 0 1 + 1 1 + 2 2 + dtype: int32 + + >>> dates = pd.Series( + ... ["2024-01-01", "2024-01-15", "2024-02-5"], dtype="datetime64[ns, UTC]" + ... ) + >>> dates.dt.day + 0 1 + 1 15 + 2 5 + dtype: int32 + >>> dates.dt.month + 0 1 + 1 1 + 2 2 + dtype: int32 + """ + def __new__(cls, data: Series): # pyright: ignore[reportInconsistentConstructor] # CombinedDatetimelikeProperties isn't really instantiated. Instead # we need to choose which parent (datetime or timedelta) is From dfd9edf37bd60d25cf4247169d458d5c58513f14 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 17:46:20 +0000 Subject: [PATCH 2/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/core/indexes/accessors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 9aa11e492f10c..3b8c5b33d6fad 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -590,7 +590,7 @@ class CombinedDatetimelikeProperties( See Also -------- pandas.Series.dt : Accessor object for datetimelike properties of the Series values. - + Examples -------- >>> dates = pd.Series( From 429f405937242addce7ab329b4b105cbcb30ffc8 Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Thu, 7 Mar 2024 14:17:02 +0530 Subject: [PATCH 3/9] update docstring with parameters --- pandas/core/indexes/accessors.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 9aa11e492f10c..ef61f385d4213 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -577,6 +577,11 @@ class CombinedDatetimelikeProperties( parent class (ArrowTemporalProperties, DatetimeProperties,TimedeltaProperties, or PeriodProperties) based on the dtype of the provided pandas Series. + Parameters + ---------- + data : pandas.Series + Series containing datetime-like data. + Raises ------ TypeError From 194b97ece4513c310d64970e21aabe5d7abb1030 Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:14:15 +0530 Subject: [PATCH 4/9] format docstring and remove from validate docstring ignore --- ci/code_checks.sh | 1 - pandas/core/indexes/accessors.py | 13 +++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 5bbad800b7aa9..182b3e30ce080 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -156,7 +156,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Period.ordinal\ pandas.PeriodIndex.freq\ pandas.PeriodIndex.qyear\ - pandas.Series.dt\ pandas.Series.dt.as_unit\ pandas.Series.dt.freq\ pandas.Series.dt.qyear\ diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index d3a680263f141..3ae6790719ac5 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -573,6 +573,7 @@ class CombinedDatetimelikeProperties( ): """ Combined datetime-like properties for a pandas Series. + Not meant to be instantiated directly. Instead, used to determine the appropriate parent class (ArrowTemporalProperties, DatetimeProperties,TimedeltaProperties, or PeriodProperties) based on the dtype of the provided pandas Series. @@ -582,19 +583,19 @@ class CombinedDatetimelikeProperties( data : pandas.Series Series containing datetime-like data. - Raises - ------ - TypeError - If object is not a pandas Series. - Returns ------- Instance of the appropriate subclass (ArrowTemporalProperties, DatetimeProperties, TimedeltaProperties, or PeriodProperties) + Raises + ------ + TypeError + If object is not a pandas Series. + See Also -------- - pandas.Series.dt : Accessor object for datetimelike properties of the Series values. + Series.dt : Accessor object for datetimelike properties of the Series values. Examples -------- From 7af2579b1a7cad8e11a37bdea20b5b7fa9fb891a Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Sat, 16 Mar 2024 20:54:44 +0530 Subject: [PATCH 5/9] Remove parameters, returns and add reference --- pandas/core/indexes/accessors.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 4a42576a10122..5f706ed0d26c1 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -579,16 +579,6 @@ class CombinedDatetimelikeProperties( parent class (ArrowTemporalProperties, DatetimeProperties,TimedeltaProperties, or PeriodProperties) based on the dtype of the provided pandas Series. - Parameters - ---------- - data : pandas.Series - Series containing datetime-like data. - - Returns - ------- - Instance of the appropriate subclass (ArrowTemporalProperties, - DatetimeProperties, TimedeltaProperties, or PeriodProperties) - Raises ------ TypeError @@ -598,6 +588,10 @@ class CombinedDatetimelikeProperties( -------- Series.dt : Accessor object for datetimelike properties of the Series values. + Notes + ----- + Reference :ref:`Series.dt ` + Examples -------- >>> dates = pd.Series( From 956ba9088b8788603818d7516d018b4f55004ea7 Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Sun, 17 Mar 2024 00:16:12 +0530 Subject: [PATCH 6/9] remove Raises, Notes and update description --- pandas/core/indexes/accessors.py | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 5f706ed0d26c1..6dccce2304653 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -573,25 +573,13 @@ class CombinedDatetimelikeProperties( DatetimeProperties, TimedeltaProperties, PeriodProperties ): """ - Combined datetime-like properties for a pandas Series. - - Not meant to be instantiated directly. Instead, used to determine the appropriate - parent class (ArrowTemporalProperties, DatetimeProperties,TimedeltaProperties, - or PeriodProperties) based on the dtype of the provided pandas Series. - - Raises - ------ - TypeError - If object is not a pandas Series. + Accessor object for datetime-like, timedelta and period properties + of the Series values. See Also -------- Series.dt : Accessor object for datetimelike properties of the Series values. - Notes - ----- - Reference :ref:`Series.dt ` - Examples -------- >>> dates = pd.Series( From 8df804145b0eef55377bbbde73d9797cb0066682 Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Sun, 17 Mar 2024 01:49:24 +0530 Subject: [PATCH 7/9] make it pass ci checks --- ci/code_checks.sh | 1 + pandas/core/indexes/accessors.py | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index ebb6fdf0c45f4..86b76155506d9 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -436,6 +436,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Series.cat.rename_categories\ pandas.Series.cat.reorder_categories\ pandas.Series.cat.set_categories\ + pandas.Series.dt\ pandas.Series.dt.as_unit\ pandas.Series.dt.ceil\ pandas.Series.dt.day_name\ diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 6dccce2304653..7261da5d5882c 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -573,8 +573,7 @@ class CombinedDatetimelikeProperties( DatetimeProperties, TimedeltaProperties, PeriodProperties ): """ - Accessor object for datetime-like, timedelta and period properties - of the Series values. + Accessor object for Series values' datetime-like, timedelta and period properties. See Also -------- From b4dea457e2a3ca0a9fda00dfab6ce6464eeb1b9b Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Sun, 17 Mar 2024 03:15:58 +0530 Subject: [PATCH 8/9] update see also --- pandas/core/indexes/accessors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 7261da5d5882c..2bb234e174563 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -577,7 +577,7 @@ class CombinedDatetimelikeProperties( See Also -------- - Series.dt : Accessor object for datetimelike properties of the Series values. + DatetimeIndex : Index of datetime64 data. Examples -------- From 5c1b24351428f7dd62a16bf9d0b97f63d7f56025 Mon Sep 17 00:00:00 2001 From: s1099 <46890315+s1099@users.noreply.github.com> Date: Sun, 17 Mar 2024 03:36:05 +0530 Subject: [PATCH 9/9] Update ci/code_checks.sh Co-authored-by: Marc Garcia --- ci/code_checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 86b76155506d9..fcbd0a855dcc8 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -436,7 +436,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Series.cat.rename_categories\ pandas.Series.cat.reorder_categories\ pandas.Series.cat.set_categories\ - pandas.Series.dt\ + pandas.Series.dt `# Accessors are implemented as classes, but we do not document the Parameters section` \ pandas.Series.dt.as_unit\ pandas.Series.dt.ceil\ pandas.Series.dt.day_name\