Skip to content

Commit 99cc9d6

Browse files
committed
Added PeriodIndex examples
1 parent d4a3a4d commit 99cc9d6

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 10 deletions
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.PeriodIndex.is_leap_year \
288278
pandas.PeriodIndex.minute \
289279
pandas.PeriodIndex.month \

pandas/_libs/tslibs/period.pyx

Lines changed: 9 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ def __arrow_array__(self, type=None):
443443
"hour",
444444
"""
445445
The hour of the period.
446+
447+
Examples
448+
--------
449+
>>> idx = pd.PeriodIndex(["2023-01-01 10:00", "2023-01-01 11:00"], freq='H')
450+
>>> idx.hour
451+
Index([10, 11], dtype='int64')
446452
""",
447453
)
448454
minute = _field_accessor(
@@ -510,6 +516,8 @@ def __arrow_array__(self, type=None):
510516
511517
Examples
512518
--------
519+
For Series:
520+
513521
>>> period = pd.period_range('2020-1-1 00:00', '2020-3-1 00:00', freq='M')
514522
>>> s = pd.Series(period)
515523
>>> s
@@ -522,6 +530,12 @@ def __arrow_array__(self, type=None):
522530
1 29
523531
2 31
524532
dtype: int64
533+
534+
For PeriodIndex:
535+
536+
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
537+
>>> idx.days_in_month # It can be also entered as `daysinmonth`
538+
Index([31, 28, 31], dtype='int64')
525539
""",
526540
)
527541
daysinmonth = days_in_month

0 commit comments

Comments
 (0)