Skip to content

DEPR: unused keywords in DTI/TDI construtors #52628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ Deprecations
- Deprecated :func:`is_int64_dtype`, check ``dtype == np.dtype(np.int64)`` instead (:issue:`52564`)
- Deprecated :func:`is_interval_dtype`, check ``isinstance(dtype, pd.IntervalDtype)`` instead (:issue:`52607`)
- Deprecated :func:`is_datetime64tz_dtype`, check ``isinstance(dtype, pd.DatetimeTZDtype)`` instead (:issue:`52607`)
- Deprecated unused "closed" and "normalize" keywords in the :class:`DatetimeIndex` constructor (:issue:`52628`)
- Deprecated unused "closed" keyword in the :class:`TimedeltaIndex` constructor (:issue:`52628`)
-

.. ---------------------------------------------------------------------------
Expand Down
28 changes: 26 additions & 2 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
cache_readonly,
doc,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_datetime64_dtype,
Expand Down Expand Up @@ -152,9 +153,15 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
Set the Timezone of the data.
normalize : bool, default False
Normalize start/end dates to midnight before generating date range.

.. deprecated:: 2.1.0

closed : {'left', 'right'}, optional
Set whether to include `start` and `end` that are on the
boundary. The default includes boundary points on either end.

.. deprecated:: 2.1.0

ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
When clocks moved backward due to DST, ambiguous times may arise.
For example in Central European Time (UTC+01), when going from 03:00
Expand Down Expand Up @@ -310,15 +317,32 @@ def __new__(
data=None,
freq: Frequency | lib.NoDefault = lib.no_default,
tz=lib.no_default,
normalize: bool = False,
closed=None,
normalize: bool | lib.NoDefault = lib.no_default,
closed=lib.no_default,
ambiguous: TimeAmbiguous = "raise",
dayfirst: bool = False,
yearfirst: bool = False,
dtype: Dtype | None = None,
copy: bool = False,
name: Hashable = None,
) -> Self:
if closed is not lib.no_default:
# GH#52628
warnings.warn(
f"The 'closed' keyword in {cls.__name__} construction is "
"deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)
if normalize is not lib.no_default:
# GH#52628
warnings.warn(
f"The 'normalize' keyword in {cls.__name__} construction is "
"deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)

if is_scalar(data):
cls._raise_scalar_data_error(data)

Expand Down
16 changes: 15 additions & 1 deletion pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING
import warnings

from pandas._libs import (
index as libindex,
Expand All @@ -12,6 +13,7 @@
Timedelta,
to_offset,
)
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
is_dtype_equal,
Expand Down Expand Up @@ -67,6 +69,9 @@ class TimedeltaIndex(DatetimeTimedeltaMixin):
One of pandas date offset strings or corresponding objects. The string
'infer' can be passed in order to set the frequency of the index as the
inferred frequency upon creation.
dtype : numpy.dtype or str, default None
Valid NumPy dtypes are timedelta64[ns]’, timedelta64[us]’,
timedelta64[ms]’, and timedelta64[s]’.
copy : bool
Make a copy of input ndarray.
name : object
Expand Down Expand Up @@ -132,11 +137,20 @@ def __new__(
data=None,
unit=None,
freq=lib.no_default,
closed=None,
closed=lib.no_default,
dtype=None,
copy: bool = False,
name=None,
):
if closed is not lib.no_default:
# GH#52628
warnings.warn(
f"The 'closed' keyword in {cls.__name__} construction is "
"deprecated and will be removed in a future version.",
FutureWarning,
stacklevel=find_stack_level(),
)

name = maybe_extract_name(name, data, cls)

if is_scalar(data):
Expand Down
12 changes: 12 additions & 0 deletions pandas/tests/indexes/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@


class TestDatetimeIndex:
def test_closed_deprecated(self):
# GH#52628
msg = "The 'closed' keyword"
with tm.assert_produces_warning(FutureWarning, match=msg):
DatetimeIndex([], closed=True)

def test_normalize_deprecated(self):
# GH#52628
msg = "The 'normalize' keyword"
with tm.assert_produces_warning(FutureWarning, match=msg):
DatetimeIndex([], normalize=True)

def test_from_dt64_unsupported_unit(self):
# GH#49292
val = np.datetime64(1, "D")
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/indexes/timedeltas/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@


class TestTimedeltaIndex:
def test_closed_deprecated(self):
# GH#52628
msg = "The 'closed' keyword"
with tm.assert_produces_warning(FutureWarning, match=msg):
TimedeltaIndex([], closed=True)

def test_array_of_dt64_nat_raises(self):
# GH#39462
nat = np.datetime64("NaT", "ns")
Expand Down