MCPcopy
hub / github.com/pandas-dev/pandas / from_ordinals

Method from_ordinals

pandas/core/indexes/period.py:322–354  ·  view source on GitHub ↗

Construct a PeriodIndex from ordinals. Parameters ---------- ordinals : array-like of int The period offsets from the proleptic Gregorian epoch. freq : str or period object One of pandas period strings or corresponding objects.

(cls, ordinals, *, freq, name=None)

Source from the content-addressed store, hash-verified

320
321 @classmethod
322 def from_ordinals(cls, ordinals, *, freq, name=None) -> Self:
323 """
324 Construct a PeriodIndex from ordinals.
325
326 Parameters
327 ----------
328 ordinals : array-like of int
329 The period offsets from the proleptic Gregorian epoch.
330 freq : str or period object
331 One of pandas period strings or corresponding objects.
332 name : str, default None
333 Name of the resulting PeriodIndex.
334
335 Returns
336 -------
337 PeriodIndex
338
339 See Also
340 --------
341 PeriodIndex.from_fields : Construct a PeriodIndex from fields
342 (year, month, day, etc.).
343 PeriodIndex.to_timestamp : Cast to DatetimeArray/Index.
344
345 Examples
346 --------
347 >>> idx = pd.PeriodIndex.from_ordinals([-1, 0, 1], freq="Q")
348 >>> idx
349 PeriodIndex(['1969Q4', '1970Q1', '1970Q2'], dtype='period[Q-DEC]')
350 """
351 ordinals = np.asarray(ordinals, dtype=np.int64)
352 dtype = PeriodDtype(freq)
353 data = PeriodArray._simple_new(ordinals, dtype=dtype)
354 return cls._simple_new(data, name=name)
355
356 # ------------------------------------------------------------------------
357 # Data

Callers 4

period_arrayFunction · 0.80
convertMethod · 0.80
test_from_ordinalsMethod · 0.80

Calls 2

PeriodDtypeClass · 0.90
_simple_newMethod · 0.45

Tested by 2

test_from_ordinalsMethod · 0.64