Skip to content

DOC: Fixing EX01 - Added examples #53468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,16 +296,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.PeriodIndex.end_time \
pandas.PeriodIndex.freqstr \
pandas.PeriodIndex.hour \
pandas.PeriodIndex.is_leap_year \
pandas.PeriodIndex.minute \
pandas.PeriodIndex.month \
pandas.PeriodIndex.quarter \
pandas.PeriodIndex.second \
pandas.PeriodIndex.week \
pandas.PeriodIndex.weekday \
pandas.PeriodIndex.weekofyear \
pandas.PeriodIndex.year \
pandas.PeriodIndex.to_timestamp \
pandas.core.window.rolling.Rolling.max \
pandas.core.window.rolling.Rolling.cov \
pandas.core.window.rolling.Rolling.skew \
Expand Down
57 changes: 57 additions & 0 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,24 @@ def __arrow_array__(self, type=None):
"year",
"""
The year of the period.

Examples
--------
>>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
>>> idx.year
Index([2023, 2024, 2025], dtype='int64')
""",
)
month = _field_accessor(
"month",
"""
The month as January=1, December=12.

Examples
--------
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
>>> idx.month
Index([1, 2, 3], dtype='int64')
""",
)
day = _field_accessor(
Expand All @@ -443,25 +455,51 @@ def __arrow_array__(self, type=None):
"minute",
"""
The minute of the period.

Examples
--------
>>> idx = pd.PeriodIndex(["2023-01-01 10:30:00",
... "2023-01-01 11:50:00"], freq='min')
>>> idx.minute
Index([30, 50], dtype='int64')
""",
)
second = _field_accessor(
"second",
"""
The second of the period.

Examples
--------
>>> idx = pd.PeriodIndex(["2023-01-01 10:00:30",
... "2023-01-01 10:00:31"], freq='s')
>>> idx.second
Index([30, 31], dtype='int64')
""",
)
weekofyear = _field_accessor(
"week",
"""
The week ordinal of the year.

Examples
--------
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
>>> idx.week # It can be written `weekofyear`
Index([5, 9, 13], dtype='int64')
""",
)
week = weekofyear
day_of_week = _field_accessor(
"day_of_week",
"""
The day of the week with Monday=0, Sunday=6.

Examples
--------
>>> idx = pd.PeriodIndex(["2023-01-01", "2023-01-02", "2023-01-03"], freq="D")
>>> idx.weekday
Index([6, 0, 1], dtype='int64')
""",
)
dayofweek = day_of_week
Expand All @@ -476,6 +514,12 @@ def __arrow_array__(self, type=None):
"quarter",
"""
The quarter of the date.

Examples
--------
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
>>> idx.quarter
Index([1, 1, 1], dtype='int64')
""",
)
qyear = _field_accessor("qyear")
Expand Down Expand Up @@ -506,6 +550,12 @@ def __arrow_array__(self, type=None):
def is_leap_year(self) -> npt.NDArray[np.bool_]:
"""
Logical indicating if the date belongs to a leap year.

Examples
--------
>>> idx = pd.PeriodIndex(["2023", "2024", "2025"], freq="Y")
>>> idx.is_leap_year
array([False, True, False])
"""
return isleapyear_arr(np.asarray(self.year))

Expand All @@ -524,6 +574,13 @@ def to_timestamp(self, freq=None, how: str = "start") -> DatetimeArray:
Returns
-------
DatetimeArray/Index

Examples
--------
>>> idx = pd.PeriodIndex(["2023-01", "2023-02", "2023-03"], freq="M")
>>> idx.to_timestamp()
DatetimeIndex(['2023-01-01', '2023-02-01', '2023-03-01'],
dtype='datetime64[ns]', freq='MS')
"""
from pandas.core.arrays import DatetimeArray

Expand Down