Skip to content

Commit f6d94a5

Browse files
jbrockmendeljreback
authored andcommitted
DEPR: enforce deprecation of unitless td64/dt64 (#30199)
1 parent f287794 commit f6d94a5

File tree

6 files changed

+23
-44
lines changed

6 files changed

+23
-44
lines changed

pandas/_libs/tslibs/timedeltas.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ class Timedelta(_Timedelta):
14601460
# also timedelta-like
14611461
return _broadcast_floordiv_td64(self.value, other, _rfloordiv)
14621462

1463-
# Includes integer array // Timedelta, deprecated in GH#19761
1463+
# Includes integer array // Timedelta, disallowed in GH#19761
14641464
raise TypeError(f'Invalid dtype {other.dtype} for __floordiv__')
14651465

14661466
elif is_float_object(other) and util.is_nan(other):

pandas/core/arrays/datetimes.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from datetime import datetime, time, timedelta
2-
import textwrap
32
from typing import Union
43
import warnings
54

@@ -2109,15 +2108,13 @@ def _validate_dt64_dtype(dtype):
21092108
if dtype is not None:
21102109
dtype = pandas_dtype(dtype)
21112110
if is_dtype_equal(dtype, np.dtype("M8")):
2112-
# no precision, warn
2111+
# no precision, disallowed GH#24806
21132112
dtype = _NS_DTYPE
2114-
msg = textwrap.dedent(
2115-
"""\
2116-
Passing in 'datetime64' dtype with no precision is deprecated
2117-
and will raise in a future version. Please pass in
2118-
'datetime64[ns]' instead."""
2113+
msg = (
2114+
"Passing in 'datetime64' dtype with no precision is not allowed. "
2115+
"Please pass in 'datetime64[ns]' instead."
21192116
)
2120-
warnings.warn(msg, FutureWarning, stacklevel=5)
2117+
raise ValueError(msg)
21212118

21222119
if (isinstance(dtype, np.dtype) and dtype != _NS_DTYPE) or not isinstance(
21232120
dtype, (np.dtype, DatetimeTZDtype)

pandas/core/arrays/timedeltas.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from datetime import timedelta
2-
import textwrap
32
from typing import List
4-
import warnings
53

64
import numpy as np
75

@@ -1123,14 +1121,13 @@ def objects_to_td64ns(data, unit="ns", errors="raise"):
11231121
def _validate_td64_dtype(dtype):
11241122
dtype = pandas_dtype(dtype)
11251123
if is_dtype_equal(dtype, np.dtype("timedelta64")):
1124+
# no precision disallowed GH#24806
11261125
dtype = _TD_DTYPE
1127-
msg = textwrap.dedent(
1128-
"""\
1129-
Passing in 'timedelta' dtype with no precision is deprecated
1130-
and will raise in a future version. Please pass in
1131-
'timedelta64[ns]' instead."""
1126+
msg = (
1127+
"Passing in 'timedelta' dtype with no precision is not allowed. "
1128+
"Please pass in 'timedelta64[ns]' instead."
11321129
)
1133-
warnings.warn(msg, FutureWarning, stacklevel=4)
1130+
raise ValueError(msg)
11341131

11351132
if not is_dtype_equal(dtype, _TD_DTYPE):
11361133
raise ValueError(_BAD_DTYPE.format(dtype=dtype))

pandas/io/pytables.py

-9
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,6 @@ class DuplicateWarning(Warning):
176176
# formats
177177
_FORMAT_MAP = {"f": "fixed", "fixed": "fixed", "t": "table", "table": "table"}
178178

179-
format_deprecate_doc = """
180-
the table keyword has been deprecated
181-
use the format='fixed(f)|table(t)' keyword instead
182-
fixed(f) : specifies the Fixed format
183-
and is the default for put operations
184-
table(t) : specifies the Table format
185-
and is the default for append operations
186-
"""
187-
188179
# storer class map
189180
_STORER_MAP = {
190181
"series": "SeriesFixed",

pandas/tests/indexes/datetimes/test_construction.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -774,18 +774,15 @@ def test_construction_with_nat_and_tzlocal(self):
774774
expected = DatetimeIndex([Timestamp("2018", tz=tz), pd.NaT])
775775
tm.assert_index_equal(result, expected)
776776

777-
def test_constructor_no_precision_warns(self):
777+
def test_constructor_no_precision_raises(self):
778778
# GH-24753, GH-24739
779-
expected = pd.DatetimeIndex(["2000"], dtype="datetime64[ns]")
780779

781-
# we set the stacklevel for DatetimeIndex
782-
with tm.assert_produces_warning(FutureWarning):
783-
result = pd.DatetimeIndex(["2000"], dtype="datetime64")
784-
tm.assert_index_equal(result, expected)
780+
msg = "with no precision is not allowed"
781+
with pytest.raises(ValueError, match=msg):
782+
pd.DatetimeIndex(["2000"], dtype="datetime64")
785783

786-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
787-
result = pd.Index(["2000"], dtype="datetime64")
788-
tm.assert_index_equal(result, expected)
784+
with pytest.raises(ValueError, match=msg):
785+
pd.Index(["2000"], dtype="datetime64")
789786

790787
def test_constructor_wrong_precision_raises(self):
791788
with pytest.raises(ValueError):

pandas/tests/indexes/timedeltas/test_construction.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,15 @@ def test_constructor_name(self):
197197
idx2 = TimedeltaIndex(idx, name="something else")
198198
assert idx2.name == "something else"
199199

200-
def test_constructor_no_precision_warns(self):
200+
def test_constructor_no_precision_raises(self):
201201
# GH-24753, GH-24739
202-
expected = pd.TimedeltaIndex(["2000"], dtype="timedelta64[ns]")
203202

204-
# we set the stacklevel for DatetimeIndex
205-
with tm.assert_produces_warning(FutureWarning):
206-
result = pd.TimedeltaIndex(["2000"], dtype="timedelta64")
207-
tm.assert_index_equal(result, expected)
203+
msg = "with no precision is not allowed"
204+
with pytest.raises(ValueError, match=msg):
205+
pd.TimedeltaIndex(["2000"], dtype="timedelta64")
208206

209-
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
210-
result = pd.Index(["2000"], dtype="timedelta64")
211-
tm.assert_index_equal(result, expected)
207+
with pytest.raises(ValueError, match=msg):
208+
pd.Index(["2000"], dtype="timedelta64")
212209

213210
def test_constructor_wrong_precision_raises(self):
214211
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)