From f6d94a53120d7ef79728c0ab0992822d61b75eb3 Mon Sep 17 00:00:00 2001 From: jbrockmendel Date: Wed, 11 Dec 2019 04:49:02 -0800 Subject: [PATCH] DEPR: enforce deprecation of unitless td64/dt64 (#30199) --- pandas/_libs/tslibs/timedeltas.pyx | 2 +- pandas/core/arrays/datetimes.py | 13 +++++-------- pandas/core/arrays/timedeltas.py | 13 +++++-------- pandas/io/pytables.py | 9 --------- .../tests/indexes/datetimes/test_construction.py | 15 ++++++--------- .../tests/indexes/timedeltas/test_construction.py | 15 ++++++--------- 6 files changed, 23 insertions(+), 44 deletions(-) diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index ddff72beab0a7..0a773b8a215ed 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -1460,7 +1460,7 @@ class Timedelta(_Timedelta): # also timedelta-like return _broadcast_floordiv_td64(self.value, other, _rfloordiv) - # Includes integer array // Timedelta, deprecated in GH#19761 + # Includes integer array // Timedelta, disallowed in GH#19761 raise TypeError(f'Invalid dtype {other.dtype} for __floordiv__') elif is_float_object(other) and util.is_nan(other): diff --git a/pandas/core/arrays/datetimes.py b/pandas/core/arrays/datetimes.py index 34e01e55d2028..2cd8aafe00f37 100644 --- a/pandas/core/arrays/datetimes.py +++ b/pandas/core/arrays/datetimes.py @@ -1,5 +1,4 @@ from datetime import datetime, time, timedelta -import textwrap from typing import Union import warnings @@ -2109,15 +2108,13 @@ def _validate_dt64_dtype(dtype): if dtype is not None: dtype = pandas_dtype(dtype) if is_dtype_equal(dtype, np.dtype("M8")): - # no precision, warn + # no precision, disallowed GH#24806 dtype = _NS_DTYPE - msg = textwrap.dedent( - """\ - Passing in 'datetime64' dtype with no precision is deprecated - and will raise in a future version. Please pass in - 'datetime64[ns]' instead.""" + msg = ( + "Passing in 'datetime64' dtype with no precision is not allowed. " + "Please pass in 'datetime64[ns]' instead." ) - warnings.warn(msg, FutureWarning, stacklevel=5) + raise ValueError(msg) if (isinstance(dtype, np.dtype) and dtype != _NS_DTYPE) or not isinstance( dtype, (np.dtype, DatetimeTZDtype) diff --git a/pandas/core/arrays/timedeltas.py b/pandas/core/arrays/timedeltas.py index 56c4a1a201eeb..b51773961811b 100644 --- a/pandas/core/arrays/timedeltas.py +++ b/pandas/core/arrays/timedeltas.py @@ -1,7 +1,5 @@ from datetime import timedelta -import textwrap from typing import List -import warnings import numpy as np @@ -1123,14 +1121,13 @@ def objects_to_td64ns(data, unit="ns", errors="raise"): def _validate_td64_dtype(dtype): dtype = pandas_dtype(dtype) if is_dtype_equal(dtype, np.dtype("timedelta64")): + # no precision disallowed GH#24806 dtype = _TD_DTYPE - msg = textwrap.dedent( - """\ - Passing in 'timedelta' dtype with no precision is deprecated - and will raise in a future version. Please pass in - 'timedelta64[ns]' instead.""" + msg = ( + "Passing in 'timedelta' dtype with no precision is not allowed. " + "Please pass in 'timedelta64[ns]' instead." ) - warnings.warn(msg, FutureWarning, stacklevel=4) + raise ValueError(msg) if not is_dtype_equal(dtype, _TD_DTYPE): raise ValueError(_BAD_DTYPE.format(dtype=dtype)) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 6c3766b5ac816..e64101585e62a 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -176,15 +176,6 @@ class DuplicateWarning(Warning): # formats _FORMAT_MAP = {"f": "fixed", "fixed": "fixed", "t": "table", "table": "table"} -format_deprecate_doc = """ -the table keyword has been deprecated -use the format='fixed(f)|table(t)' keyword instead - fixed(f) : specifies the Fixed format - and is the default for put operations - table(t) : specifies the Table format - and is the default for append operations -""" - # storer class map _STORER_MAP = { "series": "SeriesFixed", diff --git a/pandas/tests/indexes/datetimes/test_construction.py b/pandas/tests/indexes/datetimes/test_construction.py index 10f2798a29c93..2f7ed3238b767 100644 --- a/pandas/tests/indexes/datetimes/test_construction.py +++ b/pandas/tests/indexes/datetimes/test_construction.py @@ -774,18 +774,15 @@ def test_construction_with_nat_and_tzlocal(self): expected = DatetimeIndex([Timestamp("2018", tz=tz), pd.NaT]) tm.assert_index_equal(result, expected) - def test_constructor_no_precision_warns(self): + def test_constructor_no_precision_raises(self): # GH-24753, GH-24739 - expected = pd.DatetimeIndex(["2000"], dtype="datetime64[ns]") - # we set the stacklevel for DatetimeIndex - with tm.assert_produces_warning(FutureWarning): - result = pd.DatetimeIndex(["2000"], dtype="datetime64") - tm.assert_index_equal(result, expected) + msg = "with no precision is not allowed" + with pytest.raises(ValueError, match=msg): + pd.DatetimeIndex(["2000"], dtype="datetime64") - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = pd.Index(["2000"], dtype="datetime64") - tm.assert_index_equal(result, expected) + with pytest.raises(ValueError, match=msg): + pd.Index(["2000"], dtype="datetime64") def test_constructor_wrong_precision_raises(self): with pytest.raises(ValueError): diff --git a/pandas/tests/indexes/timedeltas/test_construction.py b/pandas/tests/indexes/timedeltas/test_construction.py index c8feb9e2a853a..ff6ee051755bb 100644 --- a/pandas/tests/indexes/timedeltas/test_construction.py +++ b/pandas/tests/indexes/timedeltas/test_construction.py @@ -197,18 +197,15 @@ def test_constructor_name(self): idx2 = TimedeltaIndex(idx, name="something else") assert idx2.name == "something else" - def test_constructor_no_precision_warns(self): + def test_constructor_no_precision_raises(self): # GH-24753, GH-24739 - expected = pd.TimedeltaIndex(["2000"], dtype="timedelta64[ns]") - # we set the stacklevel for DatetimeIndex - with tm.assert_produces_warning(FutureWarning): - result = pd.TimedeltaIndex(["2000"], dtype="timedelta64") - tm.assert_index_equal(result, expected) + msg = "with no precision is not allowed" + with pytest.raises(ValueError, match=msg): + pd.TimedeltaIndex(["2000"], dtype="timedelta64") - with tm.assert_produces_warning(FutureWarning, check_stacklevel=False): - result = pd.Index(["2000"], dtype="timedelta64") - tm.assert_index_equal(result, expected) + with pytest.raises(ValueError, match=msg): + pd.Index(["2000"], dtype="timedelta64") def test_constructor_wrong_precision_raises(self): with pytest.raises(ValueError):