From 6e91e0d35d2aaf84fa0fa72932bca273e832dfcd Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Tue, 5 Mar 2024 10:19:22 +0530 Subject: [PATCH 1/7] fix GL08 error for pandas.IntervalIndex.right --- ci/code_checks.sh | 1 - pandas/core/indexes/interval.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 5bbad800b7aa9..b8d859f8b7ec4 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -151,7 +151,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.IntervalIndex.left\ pandas.IntervalIndex.length\ pandas.IntervalIndex.mid\ - pandas.IntervalIndex.right\ pandas.Period.freq\ pandas.Period.ordinal\ pandas.PeriodIndex.freq\ diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index ea3e848356ab5..452cd4fa695d8 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -831,6 +831,22 @@ def left(self) -> Index: @cache_readonly def right(self) -> Index: + """ + Return intervals' right value. + Returns + ------- + Index + See Also + -------- + IntervalIndex : The structure of IntervalIndex. + Examples + -------- + >>> pd.interval_range(start=0, end=5) + IntervalIndex([(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]], + dtype='interval[int64, right]') + >>> pd.interval_range(start=0, end=5).right + Index([1, 2, 3, 4, 5], dtype='int64') + """ return Index(self._data.right, copy=False) @cache_readonly From 8549493f6d09fbb8ee9c094b931b5261efca33b3 Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Tue, 5 Mar 2024 13:38:14 +0530 Subject: [PATCH 2/7] fix GL08 error and write docstring for pandas.Series.dt --- ci/code_checks.sh | 1 - pandas/core/indexes/accessors.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index b8d859f8b7ec4..4c4e5cc640843 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -155,7 +155,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 5881f5e040370..93cab2b099367 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -571,6 +571,38 @@ 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. + Parameters + ---------- + 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) + Examples + ------- + >>> dates = pd.Series(['2024-01-01', '2024-01-15', '2024-02-5']).astype('datetime64[ns]') + >>> 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 bd6763139825a8e7281e24d82e7ec82b5ab69d1d Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:06:50 +0530 Subject: [PATCH 3/7] add See Also section and fix underline --- pandas/core/indexes/accessors.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 93cab2b099367..c3e3474665f3d 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -589,8 +589,11 @@ class CombinedDatetimelikeProperties( ------- 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']).astype('datetime64[ns]') >>> dates.dt.day 0 1 From 7a95553c0602adf2e08e5cdf00ea5cedfbc70acd Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:10:10 +0530 Subject: [PATCH 4/7] update pandas.Series.dt docstring --- pandas/core/indexes/accessors.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index c3e3474665f3d..9ea1837769e8b 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -574,21 +574,17 @@ 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. - Parameters - ---------- - data : pandas.Series - Series containing datetime-like data. + 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) + Instance of the appropriate subclass (ArrowTemporalProperties, + DatetimeProperties, TimedeltaProperties, or PeriodProperties) See Also -------- pandas.Series.dt : Accessor object for datetimelike properties of the Series values From bf38e4388e894bad2b4ba36b71126702f51c9b63 Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Tue, 5 Mar 2024 18:19:41 +0530 Subject: [PATCH 5/7] formatting and fix E501 Line too long --- pandas/core/indexes/accessors.py | 5 +++-- pandas/core/indexes/interval.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 9ea1837769e8b..5cbd993ebe772 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -587,10 +587,11 @@ class CombinedDatetimelikeProperties( DatetimeProperties, TimedeltaProperties, or PeriodProperties) See Also -------- - pandas.Series.dt : Accessor object for datetimelike properties of the Series values + 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']).astype('datetime64[ns]') + >>> dates = pd.Series(['2024-01-01', '2024-01-15', '2024-02-5'], + ... dtype='datetime64[ns]') >>> dates.dt.day 0 1 1 15 diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 452cd4fa695d8..91dec69df7469 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -833,6 +833,7 @@ def left(self) -> Index: def right(self) -> Index: """ Return intervals' right value. + Returns ------- Index From a334bf65476c71be707caf91b865b53a37c9cb48 Mon Sep 17 00:00:00 2001 From: - <46890315+s1099@users.noreply.github.com> Date: Tue, 5 Mar 2024 22:09:20 +0530 Subject: [PATCH 6/7] add newlines --- pandas/core/indexes/accessors.py | 4 ++++ pandas/core/indexes/interval.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index 5cbd993ebe772..a76b2f956f32f 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -577,17 +577,21 @@ class CombinedDatetimelikeProperties( 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'], diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 91dec69df7469..43615bccde2d0 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -837,9 +837,11 @@ def right(self) -> Index: Returns ------- Index + See Also -------- IntervalIndex : The structure of IntervalIndex. + Examples -------- >>> pd.interval_range(start=0, end=5) From e287e4ced9ee7506581cea21880bef2343d4a706 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:12:13 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pandas/core/indexes/accessors.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexes/accessors.py b/pandas/core/indexes/accessors.py index a76b2f956f32f..3dc505134c3d2 100644 --- a/pandas/core/indexes/accessors.py +++ b/pandas/core/indexes/accessors.py @@ -594,8 +594,9 @@ class CombinedDatetimelikeProperties( Examples -------- - >>> dates = pd.Series(['2024-01-01', '2024-01-15', '2024-02-5'], - ... dtype='datetime64[ns]') + >>> dates = pd.Series( + ... ["2024-01-01", "2024-01-15", "2024-02-5"], dtype="datetime64[ns]" + ... ) >>> dates.dt.day 0 1 1 15 @@ -607,6 +608,7 @@ class CombinedDatetimelikeProperties( 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