diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 9012dc6559a13..156e84c9ed964 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -101,7 +101,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.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..88c6acd6dcb42 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", @@ -1141,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. @@ -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",