diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 4b7b075ceafaf..c9c5cdc6ec4df 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -206,6 +206,7 @@ Removal of prior version deprecations/changes - :meth:`SeriesGroupBy.agg` no longer pins the name of the group to the input passed to the provided ``func`` (:issue:`51703`) - All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`) - All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`) +- Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`) - Removed the "closed" and "normalize" keywords in :meth:`DatetimeIndex.__new__` (:issue:`52628`) - Removed the "closed" and "unit" keywords in :meth:`TimedeltaIndex.__new__` (:issue:`52628`, :issue:`55499`) - All arguments in :meth:`Index.sort_values` are now keyword only (:issue:`56493`) diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index e73eba710ec39..8baf363b909fb 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -54,7 +54,6 @@ cache_readonly, doc, ) -from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.common import ( ensure_object, @@ -135,11 +134,6 @@ class PeriodArray(dtl.DatelikeOps, libperiod.PeriodMixin): # type: ignore[misc] 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`. copy : bool, default False Whether to copy the ordinals before storing. @@ -224,20 +218,7 @@ def _scalar_type(self) -> type[Period]: # -------------------------------------------------------------------- # Constructors - def __init__( - self, values, dtype: Dtype | None = None, freq=None, copy: bool = False - ) -> None: - if freq is not None: - # GH#52462 - warnings.warn( - "The 'freq' keyword in the PeriodArray constructor is deprecated " - "and will be removed in a future version. Pass 'dtype' instead", - FutureWarning, - stacklevel=find_stack_level(), - ) - freq = validate_dtype_freq(dtype, freq) - dtype = PeriodDtype(freq) - + def __init__(self, values, dtype: Dtype | None = None, copy: bool = False) -> None: if dtype is not None: dtype = pandas_dtype(dtype) if not isinstance(dtype, PeriodDtype): diff --git a/pandas/tests/arrays/period/test_constructors.py b/pandas/tests/arrays/period/test_constructors.py index d034162f1b46e..63b0e456c4566 100644 --- a/pandas/tests/arrays/period/test_constructors.py +++ b/pandas/tests/arrays/period/test_constructors.py @@ -135,17 +135,6 @@ def test_from_td64nat_sequence_raises(): pd.DataFrame(arr, dtype=dtype) -def test_freq_deprecated(): - # GH#52462 - data = np.arange(5).astype(np.int64) - msg = "The 'freq' keyword in the PeriodArray constructor is deprecated" - with tm.assert_produces_warning(FutureWarning, match=msg): - res = PeriodArray(data, freq="M") - - expected = PeriodArray(data, dtype="period[M]") - tm.assert_equal(res, expected) - - def test_period_array_from_datetime64(): arr = np.array( ["2020-01-01T00:00:00", "2020-02-02T00:00:00"], dtype="datetime64[ns]"