From f72f8823edfc52db5452b14f4d541a1b04bc0cf5 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 20 Oct 2020 14:45:43 -0700 Subject: [PATCH 1/3] CLN: make PeriodArray signature match DTA/TDA --- pandas/core/arrays/period.py | 4 ++-- pandas/core/indexes/period.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index bf2b3a0a1c9ba..2c38bbe1080c4 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -148,7 +148,7 @@ class PeriodArray(PeriodMixin, dtl.DatelikeOps): # -------------------------------------------------------------------- # Constructors - def __init__(self, values, freq=None, dtype=None, copy=False): + def __init__(self, values, dtype=None, freq=None, copy=False): freq = validate_dtype_freq(dtype, freq) if freq is not None: @@ -882,7 +882,7 @@ def period_array( if is_datetime64_dtype(data_dtype): return PeriodArray._from_datetime64(data, freq) if is_period_dtype(data_dtype): - return PeriodArray(data, freq) + return PeriodArray(data, freq=freq) # other iterable of some kind if not isinstance(data, (np.ndarray, list, tuple, ABCSeries)): diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 4f92bb7bd7a87..41968c5972ea5 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -214,7 +214,7 @@ def __new__( if data is None and ordinal is not None: # we strangely ignore `ordinal` if data is passed. ordinal = np.asarray(ordinal, dtype=np.int64) - data = PeriodArray(ordinal, freq) + data = PeriodArray(ordinal, freq=freq) else: # don't pass copy here, since we copy later. data = period_array(data=data, freq=freq) From 5dd29fc3cf59067a65074a83d85a5ca12e3b9ebc Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 20 Oct 2020 15:33:42 -0700 Subject: [PATCH 2/3] update docstring --- pandas/core/arrays/period.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index 2c38bbe1080c4..ba2048a496ef8 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -76,14 +76,14 @@ class PeriodArray(PeriodMixin, dtl.DatelikeOps): converted to ordinals without inference or copy (PeriodArray, ndarray[int64]), or a box around such an array (Series[period], PeriodIndex). + dtype : PeriodDtype, optional + A PeriodDtype instance from which to extract a `freq`. If both + `freq` and `dtype` are specified, then the frequencies must match. freq : str or DateOffset The `freq` to use for the array. Mostly applicable when `values` is an ndarray of integers, when `freq` is required. When `values` is a PeriodArray (or box around), it's checked that ``values.freq`` matches `freq`. - dtype : PeriodDtype, optional - A PeriodDtype instance from which to extract a `freq`. If both - `freq` and `dtype` are specified, then the frequencies must match. copy : bool, default False Whether to copy the ordinals before storing. From fc4eb595d8f3fb6ee9eecda1e705344e8b145883 Mon Sep 17 00:00:00 2001 From: Brock Date: Tue, 20 Oct 2020 15:47:13 -0700 Subject: [PATCH 3/3] whatsnew --- doc/source/whatsnew/v1.2.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index b4d1787697973..103008f4a7c8c 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -516,7 +516,7 @@ ExtensionArray - Fixed Bug where :class:`DataFrame` column set to scalar extension type via a dict instantion was considered an object type rather than the extension type (:issue:`35965`) - Fixed bug where ``astype()`` with equal dtype and ``copy=False`` would return a new object (:issue:`284881`) - Fixed bug when applying a NumPy ufunc with multiple outputs to a :class:`pandas.arrays.IntegerArray` returning None (:issue:`36913`) - +- Fixed an inconsistency in :class:`PeriodArray`'s ``__init__`` signature to those of :class:`DatetimeArray` and :class:`TimedeltaArray` (:issue:`37289`) Other ^^^^^