Skip to content

DEPR: unsupported dt64/td64 dtypes in pd.array #58060

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 1 commit into from
Mar 29, 2024
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Removal of prior version deprecations/changes
- All arguments except ``name`` in :meth:`Index.rename` are now keyword only (:issue:`56493`)
- All arguments except the first ``path``-like argument in IO writers are now keyword only (:issue:`54229`)
- Disallow passing a pandas type to :meth:`Index.view` (:issue:`55709`)
- Disallow units other than "s", "ms", "us", "ns" for datetime64 and timedelta64 dtypes in :func:`array` (:issue:`53817`)
- Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`)
- Removed deprecated "method" and "limit" keywords from :meth:`Series.replace` and :meth:`DataFrame.replace` (:issue:`53492`)
- Removed the "closed" and "normalize" keywords in :meth:`DatetimeIndex.__new__` (:issue:`52628`)
Expand Down
11 changes: 3 additions & 8 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
cast,
overload,
)
import warnings

import numpy as np
from numpy import ma
Expand All @@ -35,7 +34,6 @@
DtypeObj,
T,
)
from pandas.util._exceptions import find_stack_level

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

elif lib.is_np_dtype(dtype, "mM"):
warnings.warn(
raise ValueError(
# GH#53817
r"datetime64 and timedelta64 dtype resolutions other than "
r"'s', 'ms', 'us', and 'ns' are deprecated. "
r"In future releases passing unsupported resolutions will "
r"raise an exception.",
FutureWarning,
stacklevel=find_stack_level(),
r"'s', 'ms', 'us', and 'ns' are no longer supported."
)

return NumpyExtensionArray._from_sequence(data, dtype=dtype, copy=copy)
Expand Down
9 changes: 3 additions & 6 deletions pandas/tests/arrays/test_array.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import decimal
import re

import numpy as np
import pytest
Expand Down Expand Up @@ -31,15 +30,13 @@

@pytest.mark.parametrize("dtype_unit", ["M8[h]", "M8[m]", "m8[h]"])
def test_dt64_array(dtype_unit):
# PR 53817
# GH#53817
dtype_var = np.dtype(dtype_unit)
msg = (
r"datetime64 and timedelta64 dtype resolutions other than "
r"'s', 'ms', 'us', and 'ns' are deprecated. "
r"In future releases passing unsupported resolutions will "
r"raise an exception."
r"'s', 'ms', 'us', and 'ns' are no longer supported."
)
with tm.assert_produces_warning(FutureWarning, match=re.escape(msg)):
with pytest.raises(ValueError, match=msg):
pd.array([], dtype=dtype_var)


Expand Down