Skip to content

Commit 5285ff8

Browse files
authored
DOC: fix docstring validation errors for pandas.PeriodIndex (#59638)
* DOC: pandas.PeriodIndex GL08, PR07, RT03, and SA01 docstring validation errors fixed * DOC: pandas.Series.dt.qyear docstring validation error addressed by existing series.PeriodIndex.qyear docstring validation fix
1 parent ef3368a commit 5285ff8

File tree

3 files changed

+165
-23
lines changed

3 files changed

+165
-23
lines changed

ci/code_checks.sh

-22
Original file line numberDiff line numberDiff line change
@@ -81,27 +81,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
8181
-i "pandas.Period.to_timestamp SA01" \
8282
-i "pandas.PeriodDtype SA01" \
8383
-i "pandas.PeriodDtype.freq SA01" \
84-
-i "pandas.PeriodIndex.day SA01" \
85-
-i "pandas.PeriodIndex.day_of_week SA01" \
86-
-i "pandas.PeriodIndex.day_of_year SA01" \
87-
-i "pandas.PeriodIndex.dayofweek SA01" \
88-
-i "pandas.PeriodIndex.dayofyear SA01" \
89-
-i "pandas.PeriodIndex.days_in_month SA01" \
90-
-i "pandas.PeriodIndex.daysinmonth SA01" \
91-
-i "pandas.PeriodIndex.from_fields PR07,SA01" \
92-
-i "pandas.PeriodIndex.from_ordinals SA01" \
93-
-i "pandas.PeriodIndex.hour SA01" \
94-
-i "pandas.PeriodIndex.is_leap_year SA01" \
95-
-i "pandas.PeriodIndex.minute SA01" \
96-
-i "pandas.PeriodIndex.month SA01" \
97-
-i "pandas.PeriodIndex.quarter SA01" \
98-
-i "pandas.PeriodIndex.qyear GL08" \
99-
-i "pandas.PeriodIndex.second SA01" \
100-
-i "pandas.PeriodIndex.to_timestamp RT03,SA01" \
101-
-i "pandas.PeriodIndex.week SA01" \
102-
-i "pandas.PeriodIndex.weekday SA01" \
103-
-i "pandas.PeriodIndex.weekofyear SA01" \
104-
-i "pandas.PeriodIndex.year SA01" \
10584
-i "pandas.RangeIndex PR07" \
10685
-i "pandas.RangeIndex.from_range PR01,SA01" \
10786
-i "pandas.RangeIndex.start SA01" \
@@ -124,7 +103,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
124103
-i "pandas.Series.dt.month_name PR01,PR02" \
125104
-i "pandas.Series.dt.nanoseconds SA01" \
126105
-i "pandas.Series.dt.normalize PR01" \
127-
-i "pandas.Series.dt.qyear GL08" \
128106
-i "pandas.Series.dt.round PR01,PR02" \
129107
-i "pandas.Series.dt.seconds SA01" \
130108
-i "pandas.Series.dt.strftime PR01,PR02" \

pandas/core/arrays/period.py

+147-1
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,15 @@ def __arrow_array__(self, type=None):
432432
"""
433433
The year of the period.
434434
435+
See Also
436+
--------
437+
PeriodIndex.day_of_year : The ordinal day of the year.
438+
PeriodIndex.dayofyear : The ordinal day of the year.
439+
PeriodIndex.is_leap_year : Logical indicating if the date belongs to a
440+
leap year.
441+
PeriodIndex.weekofyear : The week ordinal of the year.
442+
PeriodIndex.year : The year of the period.
443+
435444
Examples
436445
--------
437446
>>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
@@ -444,6 +453,11 @@ def __arrow_array__(self, type=None):
444453
"""
445454
The month as January=1, December=12.
446455
456+
See Also
457+
--------
458+
PeriodIndex.days_in_month : The number of days in the month.
459+
PeriodIndex.daysinmonth : The number of days in the month.
460+
447461
Examples
448462
--------
449463
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
@@ -456,6 +470,16 @@ def __arrow_array__(self, type=None):
456470
"""
457471
The days of the period.
458472
473+
See Also
474+
--------
475+
PeriodIndex.day_of_week : The day of the week with Monday=0, Sunday=6.
476+
PeriodIndex.day_of_year : The ordinal day of the year.
477+
PeriodIndex.dayofweek : The day of the week with Monday=0, Sunday=6.
478+
PeriodIndex.dayofyear : The ordinal day of the year.
479+
PeriodIndex.days_in_month : The number of days in the month.
480+
PeriodIndex.daysinmonth : The number of days in the month.
481+
PeriodIndex.weekday : The day of the week with Monday=0, Sunday=6.
482+
459483
Examples
460484
--------
461485
>>> idx = pd.PeriodIndex(['2020-01-31', '2020-02-28'], freq='D')
@@ -468,6 +492,12 @@ def __arrow_array__(self, type=None):
468492
"""
469493
The hour of the period.
470494
495+
See Also
496+
--------
497+
PeriodIndex.minute : The minute of the period.
498+
PeriodIndex.second : The second of the period.
499+
PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.
500+
471501
Examples
472502
--------
473503
>>> idx = pd.PeriodIndex(["2023-01-01 10:00", "2023-01-01 11:00"], freq='h')
@@ -480,6 +510,12 @@ def __arrow_array__(self, type=None):
480510
"""
481511
The minute of the period.
482512
513+
See Also
514+
--------
515+
PeriodIndex.hour : The hour of the period.
516+
PeriodIndex.second : The second of the period.
517+
PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.
518+
483519
Examples
484520
--------
485521
>>> idx = pd.PeriodIndex(["2023-01-01 10:30:00",
@@ -493,6 +529,12 @@ def __arrow_array__(self, type=None):
493529
"""
494530
The second of the period.
495531
532+
See Also
533+
--------
534+
PeriodIndex.hour : The hour of the period.
535+
PeriodIndex.minute : The minute of the period.
536+
PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.
537+
496538
Examples
497539
--------
498540
>>> idx = pd.PeriodIndex(["2023-01-01 10:00:30",
@@ -506,6 +548,14 @@ def __arrow_array__(self, type=None):
506548
"""
507549
The week ordinal of the year.
508550
551+
See Also
552+
--------
553+
PeriodIndex.day_of_week : The day of the week with Monday=0, Sunday=6.
554+
PeriodIndex.dayofweek : The day of the week with Monday=0, Sunday=6.
555+
PeriodIndex.week : The week ordinal of the year.
556+
PeriodIndex.weekday : The day of the week with Monday=0, Sunday=6.
557+
PeriodIndex.year : The year of the period.
558+
509559
Examples
510560
--------
511561
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
@@ -519,6 +569,17 @@ def __arrow_array__(self, type=None):
519569
"""
520570
The day of the week with Monday=0, Sunday=6.
521571
572+
See Also
573+
--------
574+
PeriodIndex.day : The days of the period.
575+
PeriodIndex.day_of_week : The day of the week with Monday=0, Sunday=6.
576+
PeriodIndex.day_of_year : The ordinal day of the year.
577+
PeriodIndex.dayofweek : The day of the week with Monday=0, Sunday=6.
578+
PeriodIndex.dayofyear : The ordinal day of the year.
579+
PeriodIndex.week : The week ordinal of the year.
580+
PeriodIndex.weekday : The day of the week with Monday=0, Sunday=6.
581+
PeriodIndex.weekofyear : The week ordinal of the year.
582+
522583
Examples
523584
--------
524585
>>> idx = pd.PeriodIndex(["2023-01-01", "2023-01-02", "2023-01-03"], freq="D")
@@ -533,6 +594,17 @@ def __arrow_array__(self, type=None):
533594
"""
534595
The ordinal day of the year.
535596
597+
See Also
598+
--------
599+
PeriodIndex.day : The days of the period.
600+
PeriodIndex.day_of_week : The day of the week with Monday=0, Sunday=6.
601+
PeriodIndex.day_of_year : The ordinal day of the year.
602+
PeriodIndex.dayofweek : The day of the week with Monday=0, Sunday=6.
603+
PeriodIndex.dayofyear : The ordinal day of the year.
604+
PeriodIndex.weekday : The day of the week with Monday=0, Sunday=6.
605+
PeriodIndex.weekofyear : The week ordinal of the year.
606+
PeriodIndex.year : The year of the period.
607+
536608
Examples
537609
--------
538610
>>> idx = pd.PeriodIndex(["2023-01-10", "2023-02-01", "2023-03-01"], freq="D")
@@ -551,19 +623,74 @@ def __arrow_array__(self, type=None):
551623
"""
552624
The quarter of the date.
553625
626+
See Also
627+
--------
628+
PeriodIndex.qyear : Fiscal year the Period lies in according to its
629+
starting-quarter.
630+
554631
Examples
555632
--------
556633
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
557634
>>> idx.quarter
558635
Index([1, 1, 1], dtype='int64')
559636
""",
560637
)
561-
qyear = _field_accessor("qyear")
638+
qyear = _field_accessor(
639+
"qyear",
640+
"""
641+
Fiscal year the Period lies in according to its starting-quarter.
642+
643+
The `year` and the `qyear` of the period will be the same if the fiscal
644+
and calendar years are the same. When they are not, the fiscal year
645+
can be different from the calendar year of the period.
646+
647+
Returns
648+
-------
649+
int
650+
The fiscal year of the period.
651+
652+
See Also
653+
--------
654+
PeriodIndex.quarter : The quarter of the date.
655+
PeriodIndex.year : The year of the period.
656+
657+
Examples
658+
--------
659+
If the natural and fiscal year are the same, `qyear` and `year` will
660+
be the same.
661+
662+
>>> per = pd.Period('2018Q1', freq='Q')
663+
>>> per.qyear
664+
2018
665+
>>> per.year
666+
2018
667+
668+
If the fiscal year starts in April (`Q-MAR`), the first quarter of
669+
2018 will start in April 2017. `year` will then be 2017, but `qyear`
670+
will be the fiscal year, 2018.
671+
672+
>>> per = pd.Period('2018Q1', freq='Q-MAR')
673+
>>> per.start_time
674+
Timestamp('2017-04-01 00:00:00')
675+
>>> per.qyear
676+
2018
677+
>>> per.year
678+
2017
679+
""",
680+
)
681+
562682
days_in_month = _field_accessor(
563683
"days_in_month",
564684
"""
565685
The number of days in the month.
566686
687+
See Also
688+
--------
689+
PeriodIndex.day : The days of the period.
690+
PeriodIndex.days_in_month : The number of days in the month.
691+
PeriodIndex.daysinmonth : The number of days in the month.
692+
PeriodIndex.month : The month as January=1, December=12.
693+
567694
Examples
568695
--------
569696
For Series:
@@ -595,6 +722,12 @@ def is_leap_year(self) -> npt.NDArray[np.bool_]:
595722
"""
596723
Logical indicating if the date belongs to a leap year.
597724
725+
See Also
726+
--------
727+
PeriodIndex.qyear : Fiscal year the Period lies in according to its
728+
starting-quarter.
729+
PeriodIndex.year : The year of the period.
730+
598731
Examples
599732
--------
600733
>>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
@@ -618,6 +751,19 @@ def to_timestamp(self, freq=None, how: str = "start") -> DatetimeArray:
618751
Returns
619752
-------
620753
DatetimeArray/Index
754+
Timestamp representation of given Period-like object.
755+
756+
See Also
757+
--------
758+
PeriodIndex.day : The days of the period.
759+
PeriodIndex.from_fields : Construct a PeriodIndex from fields
760+
(year, month, day, etc.).
761+
PeriodIndex.from_ordinals : Construct a PeriodIndex from ordinals.
762+
PeriodIndex.hour : The hour of the period.
763+
PeriodIndex.minute : The minute of the period.
764+
PeriodIndex.month : The month as January=1, December=12.
765+
PeriodIndex.second : The second of the period.
766+
PeriodIndex.year : The year of the period.
621767
622768
Examples
623769
--------

pandas/core/indexes/period.py

+18
Original file line numberDiff line numberDiff line change
@@ -261,19 +261,31 @@ def from_fields(
261261
Parameters
262262
----------
263263
year : int, array, or Series, default None
264+
Year for the PeriodIndex.
264265
quarter : int, array, or Series, default None
266+
Quarter for the PeriodIndex.
265267
month : int, array, or Series, default None
268+
Month for the PeriodIndex.
266269
day : int, array, or Series, default None
270+
Day for the PeriodIndex.
267271
hour : int, array, or Series, default None
272+
Hour for the PeriodIndex.
268273
minute : int, array, or Series, default None
274+
Minute for the PeriodIndex.
269275
second : int, array, or Series, default None
276+
Second for the PeriodIndex.
270277
freq : str or period object, optional
271278
One of pandas period strings or corresponding objects.
272279
273280
Returns
274281
-------
275282
PeriodIndex
276283
284+
See Also
285+
--------
286+
PeriodIndex.from_ordinals : Construct a PeriodIndex from ordinals.
287+
PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.
288+
277289
Examples
278290
--------
279291
>>> idx = pd.PeriodIndex.from_fields(year=[2000, 2002], quarter=[1, 3])
@@ -311,6 +323,12 @@ def from_ordinals(cls, ordinals, *, freq, name=None) -> Self:
311323
-------
312324
PeriodIndex
313325
326+
See Also
327+
--------
328+
PeriodIndex.from_fields : Construct a PeriodIndex from fields
329+
(year, month, day, etc.).
330+
PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.
331+
314332
Examples
315333
--------
316334
>>> idx = pd.PeriodIndex.from_ordinals([-1, 0, 1], freq="Q")

0 commit comments

Comments
 (0)