Skip to content

DEPR: remove DTA.__init__, TDA.__init__ #58004

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 5 commits into from
Mar 26, 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
2 changes: 1 addition & 1 deletion ci/deps/actions-310.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2023.04.0
- fastparquet>=2023.10.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-311-downstream_compat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2023.04.0
- fastparquet>=2023.10.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-311.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2023.04.0
- fastparquet>=2023.10.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-312.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2023.04.0
- fastparquet>=2023.10.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-39-minimum_versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies:
- beautifulsoup4=4.11.2
- blosc=1.21.3
- bottleneck=1.3.6
- fastparquet=2023.04.0
- fastparquet=2023.10.0
- fsspec=2022.11.0
- html5lib=1.1
- hypothesis=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/actions-39.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2023.04.0
- fastparquet>=2023.10.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion ci/deps/circle-310-arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc>=1.21.3
- bottleneck>=1.3.6
- fastparquet>=2023.04.0
- fastparquet>=2023.10.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion doc/source/getting_started/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Dependency Minimum Version pip extra Notes
PyTables 3.8.0 hdf5 HDF5-based reading / writing
blosc 1.21.3 hdf5 Compression for HDF5; only available on ``conda``
zlib hdf5 Compression for HDF5
fastparquet 2023.04.0 - Parquet reading / writing (pyarrow is default)
fastparquet 2023.10.0 - Parquet reading / writing (pyarrow is default)
pyarrow 10.0.1 parquet, feather Parquet, ORC, and feather reading / writing
pyreadstat 1.2.0 spss SPSS files (.sav) reading
odfpy 1.4.1 excel Open document format (.odf, .ods, .odt) reading / writing
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Optional libraries below the lowest tested version may still work, but are not c
+------------------------+---------------------+
| Package | New Minimum Version |
+========================+=====================+
| fastparquet | 2023.04.0 |
| fastparquet | 2023.10.0 |
+------------------------+---------------------+
| adbc-driver-postgresql | 0.10.0 |
+------------------------+---------------------+
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies:
- beautifulsoup4>=4.11.2
- blosc
- bottleneck>=1.3.6
- fastparquet>=2023.04.0
- fastparquet>=2023.10.0
- fsspec>=2022.11.0
- html5lib>=1.1
- hypothesis>=6.46.1
Expand Down
2 changes: 1 addition & 1 deletion pandas/compat/_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"bs4": "4.11.2",
"blosc": "1.21.3",
"bottleneck": "1.3.6",
"fastparquet": "2023.04.0",
"fastparquet": "2023.10.0",
"fsspec": "2022.11.0",
"html5lib": "1.1",
"hypothesis": "6.46.1",
Expand Down
95 changes: 0 additions & 95 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
algos,
lib,
)
from pandas._libs.arrays import NDArrayBacked
from pandas._libs.tslibs import (
BaseOffset,
IncompatibleFrequency,
Expand Down Expand Up @@ -1936,100 +1935,6 @@ class TimelikeOps(DatetimeLikeArrayMixin):
Common ops for TimedeltaIndex/DatetimeIndex, but not PeriodIndex.
"""

_default_dtype: np.dtype

def __init__(
self, values, dtype=None, freq=lib.no_default, copy: bool = False
) -> None:
warnings.warn(
# GH#55623
f"{type(self).__name__}.__init__ is deprecated and will be "
"removed in a future version. Use pd.array instead.",
FutureWarning,
stacklevel=find_stack_level(),
)
if dtype is not None:
dtype = pandas_dtype(dtype)

values = extract_array(values, extract_numpy=True)
if isinstance(values, IntegerArray):
values = values.to_numpy("int64", na_value=iNaT)

inferred_freq = getattr(values, "_freq", None)
explicit_none = freq is None
freq = freq if freq is not lib.no_default else None

if isinstance(values, type(self)):
if explicit_none:
# don't inherit from values
pass
elif freq is None:
freq = values.freq
elif freq and values.freq:
freq = to_offset(freq)
freq = _validate_inferred_freq(freq, values.freq)

if dtype is not None and dtype != values.dtype:
# TODO: we only have tests for this for DTA, not TDA (2022-07-01)
raise TypeError(
f"dtype={dtype} does not match data dtype {values.dtype}"
)

dtype = values.dtype
values = values._ndarray

elif dtype is None:
if isinstance(values, np.ndarray) and values.dtype.kind in "Mm":
dtype = values.dtype
else:
dtype = self._default_dtype
if isinstance(values, np.ndarray) and values.dtype == "i8":
values = values.view(dtype)

if not isinstance(values, np.ndarray):
raise ValueError(
f"Unexpected type '{type(values).__name__}'. 'values' must be a "
f"{type(self).__name__}, ndarray, or Series or Index "
"containing one of those."
)
if values.ndim not in [1, 2]:
raise ValueError("Only 1-dimensional input arrays are supported.")

if values.dtype == "i8":
# for compat with datetime/timedelta/period shared methods,
# we can sometimes get here with int64 values. These represent
# nanosecond UTC (or tz-naive) unix timestamps
if dtype is None:
dtype = self._default_dtype
values = values.view(self._default_dtype)
elif lib.is_np_dtype(dtype, "mM"):
values = values.view(dtype)
elif isinstance(dtype, DatetimeTZDtype):
kind = self._default_dtype.kind
new_dtype = f"{kind}8[{dtype.unit}]"
values = values.view(new_dtype)

dtype = self._validate_dtype(values, dtype)

if freq == "infer":
raise ValueError(
f"Frequency inference not allowed in {type(self).__name__}.__init__. "
"Use 'pd.array()' instead."
)

if copy:
values = values.copy()
if freq:
freq = to_offset(freq)
if values.dtype.kind == "m" and not isinstance(freq, Tick):
raise TypeError("TimedeltaArray/Index freq must be a Tick")

NDArrayBacked.__init__(self, values=values, dtype=dtype)
self._freq = freq

if inferred_freq is None and freq is not None:
type(self)._validate_frequency(self, freq)

@classmethod
def _validate_dtype(cls, values, dtype):
raise AbstractMethodError(cls)
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class DatetimeArray(dtl.TimelikeOps, dtl.DatelikeOps): # type: ignore[misc]

Parameters
----------
values : Series, Index, DatetimeArray, ndarray
data : Series, Index, DatetimeArray, ndarray
The datetime data.

For DatetimeArray `values` (or a Series or Index boxing one),
Expand Down Expand Up @@ -287,7 +287,6 @@ def _scalar_type(self) -> type[Timestamp]:

_dtype: np.dtype[np.datetime64] | DatetimeTZDtype
_freq: BaseOffset | None = None
_default_dtype = DT64NS_DTYPE # used in TimeLikeOps.__init__

@classmethod
def _from_scalars(cls, scalars, *, dtype: DtypeObj) -> Self:
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TimedeltaArray(dtl.TimelikeOps):

Parameters
----------
values : array-like
data : array-like
The timedelta data.

dtype : numpy.dtype
Expand Down Expand Up @@ -196,7 +196,6 @@ def dtype(self) -> np.dtype[np.timedelta64]: # type: ignore[override]
# Constructors

_freq = None
_default_dtype = TD64NS_DTYPE # used in TimeLikeOps.__init__

@classmethod
def _validate_dtype(cls, values, dtype):
Expand Down
96 changes: 0 additions & 96 deletions pandas/tests/arrays/datetimes/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,6 @@ def test_from_sequence_invalid_type(self):
with pytest.raises(TypeError, match="Cannot create a DatetimeArray"):
DatetimeArray._from_sequence(mi, dtype="M8[ns]")

def test_only_1dim_accepted(self):
arr = np.array([0, 1, 2, 3], dtype="M8[h]").astype("M8[ns]")

depr_msg = "DatetimeArray.__init__ is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match="Only 1-dimensional"):
# 3-dim, we allow 2D to sneak in for ops purposes GH#29853
DatetimeArray(arr.reshape(2, 2, 1))

with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match="Only 1-dimensional"):
# 0-dim
DatetimeArray(arr[[0]].squeeze())

def test_freq_validation(self):
# GH#24623 check that invalid instances cannot be created with the
# public constructor
arr = np.arange(5, dtype=np.int64) * 3600 * 10**9

msg = (
"Inferred frequency h from passed values does not "
"conform to passed frequency W-SUN"
)
depr_msg = "DatetimeArray.__init__ is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match=msg):
DatetimeArray(arr, freq="W")

@pytest.mark.parametrize(
"meth",
[
Expand Down Expand Up @@ -76,42 +48,9 @@ def test_from_pandas_array(self):
expected = pd.date_range("1970-01-01", periods=5, freq="h")._data
tm.assert_datetime_array_equal(result, expected)

def test_mismatched_timezone_raises(self):
depr_msg = "DatetimeArray.__init__ is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
arr = DatetimeArray(
np.array(["2000-01-01T06:00:00"], dtype="M8[ns]"),
dtype=DatetimeTZDtype(tz="US/Central"),
)
dtype = DatetimeTZDtype(tz="US/Eastern")
msg = r"dtype=datetime64\[ns.*\] does not match data dtype datetime64\[ns.*\]"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(TypeError, match=msg):
DatetimeArray(arr, dtype=dtype)

# also with mismatched tzawareness
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(TypeError, match=msg):
DatetimeArray(arr, dtype=np.dtype("M8[ns]"))
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(TypeError, match=msg):
DatetimeArray(arr.tz_localize(None), dtype=arr.dtype)

def test_non_array_raises(self):
depr_msg = "DatetimeArray.__init__ is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match="list"):
DatetimeArray([1, 2, 3])

def test_bool_dtype_raises(self):
arr = np.array([1, 2, 3], dtype="bool")

depr_msg = "DatetimeArray.__init__ is deprecated"
msg = "Unexpected value for 'dtype': 'bool'. Must be"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match=msg):
DatetimeArray(arr)

msg = r"dtype bool cannot be converted to datetime64\[ns\]"
with pytest.raises(TypeError, match=msg):
DatetimeArray._from_sequence(arr, dtype="M8[ns]")
Expand All @@ -122,41 +61,6 @@ def test_bool_dtype_raises(self):
with pytest.raises(TypeError, match=msg):
pd.to_datetime(arr)

def test_incorrect_dtype_raises(self):
depr_msg = "DatetimeArray.__init__ is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match="Unexpected value for 'dtype'."):
DatetimeArray(np.array([1, 2, 3], dtype="i8"), dtype="category")

with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match="Unexpected value for 'dtype'."):
DatetimeArray(np.array([1, 2, 3], dtype="i8"), dtype="m8[s]")

with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match="Unexpected value for 'dtype'."):
DatetimeArray(np.array([1, 2, 3], dtype="i8"), dtype="M8[D]")

def test_mismatched_values_dtype_units(self):
arr = np.array([1, 2, 3], dtype="M8[s]")
dtype = np.dtype("M8[ns]")
msg = "Values resolution does not match dtype."
depr_msg = "DatetimeArray.__init__ is deprecated"

with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match=msg):
DatetimeArray(arr, dtype=dtype)

dtype2 = DatetimeTZDtype(tz="UTC", unit="ns")
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match=msg):
DatetimeArray(arr, dtype=dtype2)

def test_freq_infer_raises(self):
depr_msg = "DatetimeArray.__init__ is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with pytest.raises(ValueError, match="Frequency inference"):
DatetimeArray(np.array([1, 2, 3], dtype="i8"), freq="infer")

def test_copy(self):
data = np.array([1, 2, 3], dtype="M8[ns]")
arr = DatetimeArray._from_sequence(data, copy=False)
Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/arrays/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,12 +1320,6 @@ def test_from_pandas_array(dtype):

cls = {"M8[ns]": DatetimeArray, "m8[ns]": TimedeltaArray}[dtype]

depr_msg = f"{cls.__name__}.__init__ is deprecated"
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
result = cls(arr)
expected = cls(data)
tm.assert_extension_array_equal(result, expected)

result = cls._from_sequence(arr, dtype=dtype)
expected = cls._from_sequence(data, dtype=dtype)
tm.assert_extension_array_equal(result, expected)
Expand Down
Loading
Loading