Skip to content

Commit d1b5024

Browse files
DeaMariaLeontopper-123
authored andcommitted
DOC: Fixing EX01 - Added examples (pandas-dev#53465)
* Added some PeriodIndex examples * Added PeriodIndex examples
1 parent 2fd922f commit d1b5024

File tree

4 files changed

+43
-10
lines changed

4 files changed

+43
-10
lines changed

ci/code_checks.sh

-10
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
274274
pandas.TimedeltaIndex.as_unit \
275275
pandas.TimedeltaIndex.to_pytimedelta \
276276
pandas.TimedeltaIndex.mean \
277-
pandas.PeriodIndex.day \
278-
pandas.PeriodIndex.dayofweek \
279-
pandas.PeriodIndex.day_of_week \
280-
pandas.PeriodIndex.dayofyear \
281-
pandas.PeriodIndex.day_of_year \
282-
pandas.PeriodIndex.days_in_month \
283-
pandas.PeriodIndex.daysinmonth \
284-
pandas.PeriodIndex.end_time \
285-
pandas.PeriodIndex.freqstr \
286-
pandas.PeriodIndex.hour \
287277
pandas.core.window.rolling.Rolling.max \
288278
pandas.core.window.rolling.Rolling.cov \
289279
pandas.core.window.rolling.Rolling.skew \

pandas/_libs/tslibs/period.pyx

+9
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,15 @@ cdef class PeriodMixin:
16841684
1 2020-02-29 23:59:59.999999999
16851685
2 2020-03-31 23:59:59.999999999
16861686
dtype: datetime64[ns]
1687+
1688+
For PeriodIndex:
1689+
1690+
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
1691+
>>> idx.end_time
1692+
DatetimeIndex(['2023-01-31 23:59:59.999999999',
1693+
'2023-02-28 23:59:59.999999999',
1694+
'2023-03-31 23:59:59.999999999'],
1695+
dtype='datetime64[ns]', freq=None)
16871696
"""
16881697
return self.to_timestamp(how="end")
16891698

pandas/core/arrays/datetimelike.py

+8
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,8 @@ def freqstr(self) -> str | None:
829829
830830
Examples
831831
--------
832+
For DatetimeIndex:
833+
832834
>>> idx = pd.DatetimeIndex(["1/1/2020 10:00:00+00:00"], freq="D")
833835
>>> idx.freqstr
834836
'D'
@@ -839,6 +841,12 @@ def freqstr(self) -> str | None:
839841
... freq="infer")
840842
>>> idx.freqstr
841843
'2D'
844+
845+
For PeriodIndex:
846+
847+
>>> idx = pd.PeriodIndex(["2023-1", "2023-2", "2023-3"], freq="M")
848+
>>> idx.freqstr
849+
'M'
842850
"""
843851
if self.freq is None:
844852
return None

pandas/core/arrays/period.py

+26
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,12 @@ def __arrow_array__(self, type=None):
455455
"hour",
456456
"""
457457
The hour of the period.
458+
459+
Examples
460+
--------
461+
>>> idx = pd.PeriodIndex(["2023-01-01 10:00", "2023-01-01 11:00"], freq='H')
462+
>>> idx.hour
463+
Index([10, 11], dtype='int64')
458464
""",
459465
)
460466
minute = _field_accessor(
@@ -514,6 +520,18 @@ def __arrow_array__(self, type=None):
514520
"day_of_year",
515521
"""
516522
The ordinal day of the year.
523+
524+
Examples
525+
--------
526+
>>> idx = pd.PeriodIndex(["2023-01-10", "2023-02-01", "2023-03-01"], freq="D")
527+
>>> idx.dayofyear
528+
Index([10, 32, 60], dtype='int64')
529+
530+
>>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
531+
>>> idx
532+
PeriodIndex(['2023', '2024', '2025'], dtype='period[A-DEC]')
533+
>>> idx.dayofyear
534+
Index([365, 366, 365], dtype='int64')
517535
""",
518536
)
519537
quarter = _field_accessor(
@@ -536,6 +554,8 @@ def __arrow_array__(self, type=None):
536554
537555
Examples
538556
--------
557+
For Series:
558+
539559
>>> period = pd.period_range('2020-1-1 00:00', '2020-3-1 00:00', freq='M')
540560
>>> s = pd.Series(period)
541561
>>> s
@@ -548,6 +568,12 @@ def __arrow_array__(self, type=None):
548568
1 29
549569
2 31
550570
dtype: int64
571+
572+
For PeriodIndex:
573+
574+
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
575+
>>> idx.days_in_month # It can be also entered as `daysinmonth`
576+
Index([31, 28, 31], dtype='int64')
551577
""",
552578
)
553579
daysinmonth = days_in_month

0 commit comments

Comments
 (0)