Skip to content

Commit d12c618

Browse files
authored
DEPR: unused keywords in DTI/TDI construtors (#52628)
* DEPR: unused keywords in DTI/TDI construtors * GH refs
1 parent 37bd0fd commit d12c618

File tree

5 files changed

+61
-3
lines changed

5 files changed

+61
-3
lines changed

doc/source/whatsnew/v2.1.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ Deprecations
232232
- Deprecated :func:`is_int64_dtype`, check ``dtype == np.dtype(np.int64)`` instead (:issue:`52564`)
233233
- Deprecated :func:`is_interval_dtype`, check ``isinstance(dtype, pd.IntervalDtype)`` instead (:issue:`52607`)
234234
- Deprecated :func:`is_datetime64tz_dtype`, check ``isinstance(dtype, pd.DatetimeTZDtype)`` instead (:issue:`52607`)
235+
- Deprecated unused "closed" and "normalize" keywords in the :class:`DatetimeIndex` constructor (:issue:`52628`)
236+
- Deprecated unused "closed" keyword in the :class:`TimedeltaIndex` constructor (:issue:`52628`)
235237
-
236238

237239
.. ---------------------------------------------------------------------------

pandas/core/indexes/datetimes.py

+26-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
cache_readonly,
3030
doc,
3131
)
32+
from pandas.util._exceptions import find_stack_level
3233

3334
from pandas.core.dtypes.common import (
3435
is_datetime64_dtype,
@@ -152,9 +153,15 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
152153
Set the Timezone of the data.
153154
normalize : bool, default False
154155
Normalize start/end dates to midnight before generating date range.
156+
157+
.. deprecated:: 2.1.0
158+
155159
closed : {'left', 'right'}, optional
156160
Set whether to include `start` and `end` that are on the
157161
boundary. The default includes boundary points on either end.
162+
163+
.. deprecated:: 2.1.0
164+
158165
ambiguous : 'infer', bool-ndarray, 'NaT', default 'raise'
159166
When clocks moved backward due to DST, ambiguous times may arise.
160167
For example in Central European Time (UTC+01), when going from 03:00
@@ -310,15 +317,32 @@ def __new__(
310317
data=None,
311318
freq: Frequency | lib.NoDefault = lib.no_default,
312319
tz=lib.no_default,
313-
normalize: bool = False,
314-
closed=None,
320+
normalize: bool | lib.NoDefault = lib.no_default,
321+
closed=lib.no_default,
315322
ambiguous: TimeAmbiguous = "raise",
316323
dayfirst: bool = False,
317324
yearfirst: bool = False,
318325
dtype: Dtype | None = None,
319326
copy: bool = False,
320327
name: Hashable = None,
321328
) -> Self:
329+
if closed is not lib.no_default:
330+
# GH#52628
331+
warnings.warn(
332+
f"The 'closed' keyword in {cls.__name__} construction is "
333+
"deprecated and will be removed in a future version.",
334+
FutureWarning,
335+
stacklevel=find_stack_level(),
336+
)
337+
if normalize is not lib.no_default:
338+
# GH#52628
339+
warnings.warn(
340+
f"The 'normalize' keyword in {cls.__name__} construction is "
341+
"deprecated and will be removed in a future version.",
342+
FutureWarning,
343+
stacklevel=find_stack_level(),
344+
)
345+
322346
if is_scalar(data):
323347
cls._raise_scalar_data_error(data)
324348

pandas/core/indexes/timedeltas.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33

44
from typing import TYPE_CHECKING
5+
import warnings
56

67
from pandas._libs import (
78
index as libindex,
@@ -12,6 +13,7 @@
1213
Timedelta,
1314
to_offset,
1415
)
16+
from pandas.util._exceptions import find_stack_level
1517

1618
from pandas.core.dtypes.common import (
1719
is_dtype_equal,
@@ -67,6 +69,9 @@ class TimedeltaIndex(DatetimeTimedeltaMixin):
6769
One of pandas date offset strings or corresponding objects. The string
6870
'infer' can be passed in order to set the frequency of the index as the
6971
inferred frequency upon creation.
72+
dtype : numpy.dtype or str, default None
73+
Valid NumPy dtypes are timedelta64[ns]’, timedelta64[us]’,
74+
timedelta64[ms]’, and timedelta64[s]’.
7075
copy : bool
7176
Make a copy of input ndarray.
7277
name : object
@@ -132,11 +137,20 @@ def __new__(
132137
data=None,
133138
unit=None,
134139
freq=lib.no_default,
135-
closed=None,
140+
closed=lib.no_default,
136141
dtype=None,
137142
copy: bool = False,
138143
name=None,
139144
):
145+
if closed is not lib.no_default:
146+
# GH#52628
147+
warnings.warn(
148+
f"The 'closed' keyword in {cls.__name__} construction is "
149+
"deprecated and will be removed in a future version.",
150+
FutureWarning,
151+
stacklevel=find_stack_level(),
152+
)
153+
140154
name = maybe_extract_name(name, data, cls)
141155

142156
if is_scalar(data):

pandas/tests/indexes/datetimes/test_constructors.py

+12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@
3333

3434

3535
class TestDatetimeIndex:
36+
def test_closed_deprecated(self):
37+
# GH#52628
38+
msg = "The 'closed' keyword"
39+
with tm.assert_produces_warning(FutureWarning, match=msg):
40+
DatetimeIndex([], closed=True)
41+
42+
def test_normalize_deprecated(self):
43+
# GH#52628
44+
msg = "The 'normalize' keyword"
45+
with tm.assert_produces_warning(FutureWarning, match=msg):
46+
DatetimeIndex([], normalize=True)
47+
3648
def test_from_dt64_unsupported_unit(self):
3749
# GH#49292
3850
val = np.datetime64(1, "D")

pandas/tests/indexes/timedeltas/test_constructors.py

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818

1919

2020
class TestTimedeltaIndex:
21+
def test_closed_deprecated(self):
22+
# GH#52628
23+
msg = "The 'closed' keyword"
24+
with tm.assert_produces_warning(FutureWarning, match=msg):
25+
TimedeltaIndex([], closed=True)
26+
2127
def test_array_of_dt64_nat_raises(self):
2228
# GH#39462
2329
nat = np.datetime64("NaT", "ns")

0 commit comments

Comments
 (0)