Skip to content

Commit

Permalink
DEPR: freq keyword in PeriodArray (#58022)
Browse files Browse the repository at this point in the history
* DEPR: freq keyword in PeriodArray

* update docstring
  • Loading branch information
jbrockmendel committed Mar 27, 2024
1 parent 2e80a5b commit c7d4edf
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 31 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Expand Up @@ -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`)
Expand Down
21 changes: 1 addition & 20 deletions pandas/core/arrays/period.py
Expand Up @@ -54,7 +54,6 @@
cache_readonly,
doc,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
ensure_object,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
11 changes: 0 additions & 11 deletions pandas/tests/arrays/period/test_constructors.py
Expand Up @@ -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]"
Expand Down

0 comments on commit c7d4edf

Please sign in to comment.