Skip to content

Period index 29204 #29224

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

Closed
wants to merge 9 commits into from
Closed
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
21 changes: 16 additions & 5 deletions pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,18 @@ def to_timestamp(self, freq=None, how="start"):
----------
freq : str or DateOffset, optional
Target frequency. The default is 'D' for week or longer,
'S' otherwise
'S' otherwise.
how : {'s', 'e', 'start', 'end'}
Convert to timestamp using start or end of period.
*args
Positional arguments passed.
**kwargs
Keyword arguments passed.

Returns
-------
DatetimeArray/Index
As a timestamp.
"""
from pandas.core.arrays import DatetimeArray

Expand Down Expand Up @@ -539,17 +545,22 @@ def asfreq(self, freq=None, how="E"):
Parameters
----------
freq : str
a frequency
A frequency.
how : str {'E', 'S'}
'E', 'END', or 'FINISH' for end,
'S', 'START', or 'BEGIN' for start.
Use 'E', 'END', or 'FINISH' for end,
Use 'S', 'START', or 'BEGIN' for start.
Whether the elements should be aligned to the end
or start within pa period. January 31st ('END') vs.
January 1st ('START') for example.
*args
Positional arguments passed.
**kwargs
Keyword arguments passed.

Returns
-------
new : Period Array/Index with the new frequency
PeriodArray or PeriodIndex
Wwith the new frequency.

Examples
--------
Expand Down
40 changes: 26 additions & 14 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,24 @@ class PeriodDelegateMixin(DatetimelikeDelegateMixin):
)
class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):
"""
Immutable ndarray holding ordinal values indicating regular periods in
time such as particular years, quarters, months, etc.
Holds ordinal time values.

Index keys are boxed to Period objects which carries the metadata (eg,
frequency information).
An immutable ndarray. Indicates regular periods in time such as particular years,
quarters, months, etc. Index keys are boxed to Period objects which carries the
metadata (eg, frequency information). If `ordinal` and `data` are not used, the
time values are passed to :meth: `_generate_range()`.

Parameters
----------
name : default None
A name for the data.
ordinal : default None
data : array-like (1d int np.ndarray or PeriodArray), optional
Optional period-like data to construct index with
Optional period-like data to construct index with.
copy : bool
Make a copy of input ndarray
Make a copy of input ndarray.
freq : str or period object, optional
One of pandas period strings or corresponding objects
One of pandas period strings or corresponding objects.
start : starting value, period-like, optional
If data is None, used as the start point in generating regular
period data.
Expand All @@ -99,25 +103,32 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):

periods : int, optional, > 0
Number of periods to generate, if generating index. Takes precedence
over end argument
over end argument.

.. deprecated:: 0.24.0

end : end value, period-like, optional
If periods is none, generated index will extend to first conforming
period on or just past end argument
period on or just past end argument.

.. deprecated:: 0.24.0

year : int, array, or Series, default None
Year value of period.
month : int, array, or Series, default None
Month value of period.
quarter : int, array, or Series, default None
Quarter value of period.
day : int, array, or Series, default None
Day value of period.
hour : int, array, or Series, default None
Hour value of period.
minute : int, array, or Series, default None
Minute value of period.
second : int, array, or Series, default None
Second value of period.
tz : object, default None
Timezone for converting datetime64 data to Periods
Timezone for converting datetime64 data to Periods.
dtype : str or PeriodDtype, default None

Attributes
Expand Down Expand Up @@ -161,11 +172,12 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index, PeriodDelegateMixin):
-----
Creating a PeriodIndex based on `start`, `periods`, and `end` has
been deprecated in favor of :func:`period_range`.

Examples
--------
>>> idx = pd.PeriodIndex(year=year_arr, quarter=q_arr)
"""
# Example not currently passing tests
# Examples
# --------
# >>> idx = pd.PeriodIndex(year=year_arr, quarter=q_arr)
# """

_typ = "periodindex"
_attributes = ["name", "freq"]
Expand Down