From 561ae13034c9913977c54319278abe3e97e84d65 Mon Sep 17 00:00:00 2001 From: githubalexliu Date: Thu, 29 Aug 2024 20:30:43 -0400 Subject: [PATCH 1/3] DOCS: fix docstring validation error for pandas.Series --- ci/code_checks.sh | 2 -- pandas/core/arrays/datetimes.py | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 72678be1587f8..0096b42d332fe 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -123,8 +123,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Series.dt.microseconds SA01" \ -i "pandas.Series.dt.month_name PR01,PR02" \ -i "pandas.Series.dt.nanoseconds SA01" \ - -i "pandas.Series.dt.normalize PR01" \ - -i "pandas.Series.dt.qyear GL08" \ -i "pandas.Series.dt.round PR01,PR02" \ -i "pandas.Series.dt.seconds SA01" \ -i "pandas.Series.dt.strftime PR01,PR02" \ diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 201c449185057..99d22466afad8 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -250,6 +250,7 @@ def _scalar_type(self) -> type[Timestamp]: "dayofyear", "day_of_year", "quarter", + "qyear", "days_in_month", "daysinmonth", "microsecond", @@ -1152,6 +1153,15 @@ def normalize(self) -> Self: This method is available on Series with datetime values under the ``.dt`` accessor, and directly on Datetime Array/Index. + Parameters + ---------- + *args : any, default None + Additional keywords have no effect but might be accepted for + compatibility with NumPy. + **kwargs : any, default None + Additional keywords have no effect but might be accepted for + compatibility with NumPy. + Returns ------- DatetimeArray, DatetimeIndex or Series @@ -1919,6 +1929,50 @@ def isocalendar(self) -> DataFrame: Index([1, 1], dtype='int32') """, ) + qyear = _field_accessor( + "qyear", + "qy", + """ + Fiscal year the Period lies in according to its starting-quarter. + + The `year` and the `qyear` of the period will be the same if the fiscal + and calendar years are the same. When they are not, the fiscal year + can be different from the calendar year of the period. + + Returns + ------- + int + The fiscal year of the period. + + See Also + -------- + DatetimeIndex.year : Return the calendar year of the date. + DatetimeIndex.quarter : Return the quarter of the date + + Examples + -------- + If the natural and fiscal year are the same, `qyear` and `year` will + be the same. + + >>> per = pd.Period('2018Q1', freq='Q') + >>> per.qyear + 2018 + >>> per.year + 2018 + + If the fiscal year starts in April (`Q-MAR`), the first quarter of + 2018 will start in April 2017. `year` will then be 2017, but `qyear` + will be the fiscal year, 2018. + + >>> per = pd.Period('2018Q1', freq='Q-MAR') + >>> per.start_time + Timestamp('2017-04-01 00:00:00') + >>> per.qyear + 2018 + >>> per.year + 2017 + """, + ) days_in_month = _field_accessor( "days_in_month", "dim", From e12308c43323390dfbf0bbb97db1f0420ed8e4d1 Mon Sep 17 00:00:00 2001 From: githubalexliu Date: Fri, 6 Sep 2024 16:13:01 -0400 Subject: [PATCH 2/3] Added *args and **kwargs parameter for normalize --- pandas/core/arrays/datetimes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 99d22466afad8..95e256268a27d 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1142,7 +1142,7 @@ def to_pydatetime(self) -> npt.NDArray[np.object_]: """ return ints_to_pydatetime(self.asi8, tz=self.tz, reso=self._creso) - def normalize(self) -> Self: + def normalize(self, *args, **kwargs) -> Self: """ Convert times to midnight. From 8ef0b968104760e4ea6598a463276c2236bcbd58 Mon Sep 17 00:00:00 2001 From: githubalexliu Date: Fri, 6 Sep 2024 16:13:38 -0400 Subject: [PATCH 3/3] DOCS: Added period for DatetimeIndex.quarter --- pandas/core/arrays/datetimes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 95e256268a27d..88c6acd6dcb42 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1947,7 +1947,7 @@ def isocalendar(self) -> DataFrame: See Also -------- DatetimeIndex.year : Return the calendar year of the date. - DatetimeIndex.quarter : Return the quarter of the date + DatetimeIndex.quarter : Return the quarter of the date. Examples --------