@@ -94,39 +94,24 @@ class PeriodIndex(DatetimeIndexOpsMixin):
94
94
----------
95
95
data : array-like (1d int np.ndarray or PeriodArray), optional
96
96
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.
110
99
111
100
.. 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.
126
112
127
113
.. deprecated:: 2.2.0
128
114
Use PeriodIndex.from_fields instead.
129
- dtype : str or PeriodDtype, default None
130
115
131
116
Attributes
132
117
----------
@@ -171,7 +156,7 @@ class PeriodIndex(DatetimeIndexOpsMixin):
171
156
172
157
Examples
173
158
--------
174
- >>> idx = pd.PeriodIndex.from_fields(year=[2000, 2002 ], quarter=[1, 3] )
159
+ >>> idx = pd.PeriodIndex(data=['2000Q1', '2002Q3' ], freq='Q' )
175
160
>>> idx
176
161
PeriodIndex(['2000Q1', '2002Q3'], dtype='period[Q-DEC]')
177
162
"""
@@ -331,6 +316,31 @@ def from_fields(
331
316
second = None ,
332
317
freq = None ,
333
318
) -> 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
+ """
334
344
fields = {
335
345
"year" : year ,
336
346
"quarter" : quarter ,
@@ -346,6 +356,28 @@ def from_fields(
346
356
347
357
@classmethod
348
358
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
+ """
349
381
ordinals = np .asarray (ordinals , dtype = np .int64 )
350
382
dtype = PeriodDtype (freq )
351
383
data = PeriodArray ._simple_new (ordinals , dtype = dtype )
0 commit comments