Skip to content

Commit a1adb89

Browse files
yuanx749pmhatre1
authored andcommitted
Fix errors in docstring for pandas.PeriodIndex (pandas-dev#57247)
* Fix docstring errors * Update
1 parent c78f125 commit a1adb89

File tree

2 files changed

+61
-30
lines changed

2 files changed

+61
-30
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
9090
pandas.TimedeltaIndex.round\
9191
pandas.TimedeltaIndex.floor\
9292
pandas.TimedeltaIndex.ceil\
93-
pandas.PeriodIndex\
9493
pandas.PeriodIndex.strftime\
9594
pandas.Series.rename_axis\
9695
pandas.Series.dt.to_period\

pandas/core/indexes/period.py

+61-29
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,24 @@ class PeriodIndex(DatetimeIndexOpsMixin):
9494
----------
9595
data : array-like (1d int np.ndarray or PeriodArray), optional
9696
Optional period-like data to construct index with.
97-
copy : bool
98-
Make a copy of input ndarray.
99-
freq : str or period object, optional
100-
One of pandas period strings or corresponding objects.
101-
year : int, array, or Series, default None
102-
103-
.. deprecated:: 2.2.0
104-
Use PeriodIndex.from_fields instead.
105-
month : int, array, or Series, default None
106-
107-
.. deprecated:: 2.2.0
108-
Use PeriodIndex.from_fields instead.
109-
quarter : int, array, or Series, default None
97+
ordinal : array-like of int, optional
98+
The period offsets from the proleptic Gregorian epoch.
11099
111100
.. deprecated:: 2.2.0
112-
Use PeriodIndex.from_fields instead.
113-
day : int, array, or Series, default None
114-
115-
.. deprecated:: 2.2.0
116-
Use PeriodIndex.from_fields instead.
117-
hour : int, array, or Series, default None
118-
119-
.. deprecated:: 2.2.0
120-
Use PeriodIndex.from_fields instead.
121-
minute : int, array, or Series, default None
122-
123-
.. deprecated:: 2.2.0
124-
Use PeriodIndex.from_fields instead.
125-
second : int, array, or Series, default None
101+
Use PeriodIndex.from_ordinals instead.
102+
freq : str or period object, optional
103+
One of pandas period strings or corresponding objects.
104+
dtype : str or PeriodDtype, default None
105+
A dtype from which to extract a freq.
106+
copy : bool
107+
Make a copy of input ndarray.
108+
name : str, default None
109+
Name of the resulting PeriodIndex.
110+
**fields : optional
111+
Date fields such as year, month, etc.
126112
127113
.. deprecated:: 2.2.0
128114
Use PeriodIndex.from_fields instead.
129-
dtype : str or PeriodDtype, default None
130115
131116
Attributes
132117
----------
@@ -171,7 +156,7 @@ class PeriodIndex(DatetimeIndexOpsMixin):
171156
172157
Examples
173158
--------
174-
>>> idx = pd.PeriodIndex.from_fields(year=[2000, 2002], quarter=[1, 3])
159+
>>> idx = pd.PeriodIndex(data=['2000Q1', '2002Q3'], freq='Q')
175160
>>> idx
176161
PeriodIndex(['2000Q1', '2002Q3'], dtype='period[Q-DEC]')
177162
"""
@@ -331,6 +316,31 @@ def from_fields(
331316
second=None,
332317
freq=None,
333318
) -> Self:
319+
"""
320+
Construct a PeriodIndex from fields (year, month, day, etc.).
321+
322+
Parameters
323+
----------
324+
year : int, array, or Series, default None
325+
quarter : int, array, or Series, default None
326+
month : int, array, or Series, default None
327+
day : int, array, or Series, default None
328+
hour : int, array, or Series, default None
329+
minute : int, array, or Series, default None
330+
second : int, array, or Series, default None
331+
freq : str or period object, optional
332+
One of pandas period strings or corresponding objects.
333+
334+
Returns
335+
-------
336+
PeriodIndex
337+
338+
Examples
339+
--------
340+
>>> idx = pd.PeriodIndex.from_fields(year=[2000, 2002], quarter=[1, 3])
341+
>>> idx
342+
PeriodIndex(['2000Q1', '2002Q3'], dtype='period[Q-DEC]')
343+
"""
334344
fields = {
335345
"year": year,
336346
"quarter": quarter,
@@ -346,6 +356,28 @@ def from_fields(
346356

347357
@classmethod
348358
def from_ordinals(cls, ordinals, *, freq, name=None) -> Self:
359+
"""
360+
Construct a PeriodIndex from ordinals.
361+
362+
Parameters
363+
----------
364+
ordinals : array-like of int
365+
The period offsets from the proleptic Gregorian epoch.
366+
freq : str or period object
367+
One of pandas period strings or corresponding objects.
368+
name : str, default None
369+
Name of the resulting PeriodIndex.
370+
371+
Returns
372+
-------
373+
PeriodIndex
374+
375+
Examples
376+
--------
377+
>>> idx = pd.PeriodIndex.from_ordinals([-1, 0, 1], freq='Q')
378+
>>> idx
379+
PeriodIndex(['1969Q4', '1970Q1', '1970Q2'], dtype='period[Q-DEC]')
380+
"""
349381
ordinals = np.asarray(ordinals, dtype=np.int64)
350382
dtype = PeriodDtype(freq)
351383
data = PeriodArray._simple_new(ordinals, dtype=dtype)

0 commit comments

Comments
 (0)