Skip to content

Commit 49898b7

Browse files
jbrockmendelpmhatre1
authored andcommitted
DEPR: unsupported dt64/td64 dtypes in pd.array (pandas-dev#58060)
1 parent 2b76841 commit 49898b7

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Removal of prior version deprecations/changes
207207
- All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`)
208208
- All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`)
209209
- Disallow passing a pandas type to :meth:`Index.view` (:issue:`55709`)
210+
- Disallow units other than "s", "ms", "us", "ns" for datetime64 and timedelta64 dtypes in :func:`array` (:issue:`53817`)
210211
- Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`)
211212
- Removed deprecated "method" and "limit" keywords from :meth:`Series.replace` and :meth:`DataFrame.replace` (:issue:`53492`)
212213
- Removed the "closed" and "normalize" keywords in :meth:`DatetimeIndex.__new__` (:issue:`52628`)

pandas/core/construction.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
cast,
1616
overload,
1717
)
18-
import warnings
1918

2019
import numpy as np
2120
from numpy import ma
@@ -35,7 +34,6 @@
3534
DtypeObj,
3635
T,
3736
)
38-
from pandas.util._exceptions import find_stack_level
3937

4038
from pandas.core.dtypes.base import ExtensionDtype
4139
from pandas.core.dtypes.cast import (
@@ -373,13 +371,10 @@ def array(
373371
return TimedeltaArray._from_sequence(data, dtype=dtype, copy=copy)
374372

375373
elif lib.is_np_dtype(dtype, "mM"):
376-
warnings.warn(
374+
raise ValueError(
375+
# GH#53817
377376
r"datetime64 and timedelta64 dtype resolutions other than "
378-
r"'s', 'ms', 'us', and 'ns' are deprecated. "
379-
r"In future releases passing unsupported resolutions will "
380-
r"raise an exception.",
381-
FutureWarning,
382-
stacklevel=find_stack_level(),
377+
r"'s', 'ms', 'us', and 'ns' are no longer supported."
383378
)
384379

385380
return NumpyExtensionArray._from_sequence(data, dtype=dtype, copy=copy)

pandas/tests/arrays/test_array.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
22
import decimal
3-
import re
43

54
import numpy as np
65
import pytest
@@ -31,15 +30,13 @@
3130

3231
@pytest.mark.parametrize("dtype_unit", ["M8[h]", "M8[m]", "m8[h]"])
3332
def test_dt64_array(dtype_unit):
34-
# PR 53817
33+
# GH#53817
3534
dtype_var = np.dtype(dtype_unit)
3635
msg = (
3736
r"datetime64 and timedelta64 dtype resolutions other than "
38-
r"'s', 'ms', 'us', and 'ns' are deprecated. "
39-
r"In future releases passing unsupported resolutions will "
40-
r"raise an exception."
37+
r"'s', 'ms', 'us', and 'ns' are no longer supported."
4138
)
42-
with tm.assert_produces_warning(FutureWarning, match=re.escape(msg)):
39+
with pytest.raises(ValueError, match=msg):
4340
pd.array([], dtype=dtype_var)
4441

4542

0 commit comments

Comments
 (0)