Skip to content

Commit 4e7ade7

Browse files
authored
DEPR: DTA(float_data, dtype=dt64tz) (#49361)
DEPR: DTA.astype unitless, DTA(float_data, dtype=dt64tz)
1 parent fb9b345 commit 4e7ade7

File tree

4 files changed

+9
-45
lines changed

4 files changed

+9
-45
lines changed

doc/source/whatsnew/v2.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ Removal of prior version deprecations/changes
298298
- Changed the behavior of :class:`Series` constructor, it will no longer infer a datetime64 or timedelta64 dtype from string entries (:issue:`41731`)
299299
- Changed behavior of :class:`Timestamp` constructor with a ``np.datetime64`` object and a ``tz`` passed to interpret the input as a wall-time as opposed to a UTC time (:issue:`42288`)
300300
- Changed behavior of :class:`Index` constructor when passed a ``SparseArray`` or ``SparseDtype`` to retain that dtype instead of casting to ``numpy.ndarray`` (:issue:`43930`)
301+
- Changed behavior of :class:`Index`, :class:`Series`, :class:`DataFrame` constructors with floating-dtype data and a :class:`DatetimeTZDtype`, the data are now interpreted as UTC-times instead of wall-times, consistent with how integer-dtype data are treated (:issue:`45573`)
301302
- Removed the deprecated ``base`` and ``loffset`` arguments from :meth:`pandas.DataFrame.resample`, :meth:`pandas.Series.resample` and :class:`pandas.Grouper`. Use ``offset`` or ``origin`` instead (:issue:`31809`)
302303
- Changed behavior of :meth:`DataFrame.any` and :meth:`DataFrame.all` with ``bool_only=True``; object-dtype columns with all-bool values will no longer be included, manually cast to ``bool`` dtype first (:issue:`46188`)
303304
- Changed behavior of comparison of a :class:`Timestamp` with a ``datetime.date`` object; these now compare as un-equal and raise on inequality comparisons, matching the ``datetime.datetime`` behavior (:issue:`36131`)

pandas/core/arrays/datetimes.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -2230,27 +2230,10 @@ def maybe_convert_dtype(data, copy: bool, tz: tzinfo | None = None):
22302230
return data, copy
22312231

22322232
if is_float_dtype(data.dtype):
2233-
# Note: we must cast to datetime64[ns] here in order to treat these
2234-
# as wall-times instead of UTC timestamps.
2235-
data = data.astype(DT64NS_DTYPE)
2233+
# pre-2.0 we treated these as wall-times, inconsistent with ints
2234+
# GH#23675, GH#45573 deprecated to treat symmetrically with integer dtypes
2235+
data = data.astype(np.int64)
22362236
copy = False
2237-
if (
2238-
tz is not None
2239-
and len(data) > 0
2240-
and not timezones.is_utc(timezones.maybe_get_tz(tz))
2241-
):
2242-
# GH#23675, GH#45573 deprecate to treat symmetrically with integer dtypes
2243-
warnings.warn(
2244-
"The behavior of DatetimeArray._from_sequence with a timezone-aware "
2245-
"dtype and floating-dtype data is deprecated. In a future version, "
2246-
"this data will be interpreted as nanosecond UTC timestamps "
2247-
"instead of wall-times, matching the behavior with integer dtypes. "
2248-
"To retain the old behavior, explicitly cast to 'datetime64[ns]' "
2249-
"before passing the data to pandas. To get the future behavior, "
2250-
"first cast to 'int64'.",
2251-
FutureWarning,
2252-
stacklevel=find_stack_level(),
2253-
)
22542237

22552238
elif is_timedelta64_dtype(data.dtype) or is_bool_dtype(data.dtype):
22562239
# GH#29794 enforcing deprecation introduced in GH#23539

pandas/tests/dtypes/test_missing.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -426,11 +426,9 @@ def test_array_equivalent(dtype_equal):
426426
dtype_equal=dtype_equal,
427427
)
428428

429-
msg = "will be interpreted as nanosecond UTC timestamps instead of wall-times"
430-
with tm.assert_produces_warning(FutureWarning, match=msg):
431-
dti1 = DatetimeIndex([0, np.nan], tz="US/Eastern")
432-
dti2 = DatetimeIndex([0, np.nan], tz="CET")
433-
dti3 = DatetimeIndex([1, np.nan], tz="US/Eastern")
429+
dti1 = DatetimeIndex([0, np.nan], tz="US/Eastern")
430+
dti2 = DatetimeIndex([0, np.nan], tz="CET")
431+
dti3 = DatetimeIndex([1, np.nan], tz="US/Eastern")
434432

435433
assert array_equivalent(
436434
dti1,
@@ -444,7 +442,7 @@ def test_array_equivalent(dtype_equal):
444442
)
445443
# The rest are not dtype_equal
446444
assert not array_equivalent(DatetimeIndex([0, np.nan]), dti1)
447-
assert not array_equivalent(
445+
assert array_equivalent(
448446
dti2,
449447
dti1,
450448
)

pandas/tests/series/methods/test_astype.py

+1-19
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,7 @@ def test_astype_nan_to_bool(self):
395395
def test_astype_ea_to_datetimetzdtype(self, dtype):
396396
# GH37553
397397
ser = Series([4, 0, 9], dtype=dtype)
398-
warn = FutureWarning if ser.dtype.kind == "f" else None
399-
msg = "with a timezone-aware dtype and floating-dtype data"
400-
with tm.assert_produces_warning(warn, match=msg):
401-
result = ser.astype(DatetimeTZDtype(tz="US/Pacific"))
398+
result = ser.astype(DatetimeTZDtype(tz="US/Pacific"))
402399

403400
expected = Series(
404401
{
@@ -408,21 +405,6 @@ def test_astype_ea_to_datetimetzdtype(self, dtype):
408405
}
409406
)
410407

411-
if dtype in tm.FLOAT_EA_DTYPES:
412-
expected = Series(
413-
{
414-
0: Timestamp(
415-
"1970-01-01 00:00:00.000000004-08:00", tz="US/Pacific"
416-
),
417-
1: Timestamp(
418-
"1970-01-01 00:00:00.000000000-08:00", tz="US/Pacific"
419-
),
420-
2: Timestamp(
421-
"1970-01-01 00:00:00.000000009-08:00", tz="US/Pacific"
422-
),
423-
}
424-
)
425-
426408
tm.assert_series_equal(result, expected)
427409

428410
def test_astype_retain_Attrs(self, any_numpy_dtype):

0 commit comments

Comments
 (0)