Skip to content

Commit 657c1d3

Browse files
mroeschkeproost
authored andcommitted
DEPR: tz_convert in the Timestamp constructor raises (pandas-dev#29929)
1 parent e7be89e commit 657c1d3

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

doc/source/whatsnew/v1.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
466466
- Changed the default ``fill_value`` in :meth:`Categorical.take` from ``True`` to ``False`` (:issue:`20841`)
467467
- Changed the default value for the `raw` argument in :func:`Series.rolling().apply() <pandas.core.window.Rolling.apply>`, :func:`DataFrame.rolling().apply() <pandas.core.window.Rolling.apply>`,
468468
- :func:`Series.expanding().apply() <pandas.core.window.Expanding.apply>`, and :func:`DataFrame.expanding().apply() <pandas.core.window.Expanding.apply>` to ``False`` (:issue:`20584`)
469+
- Passing a tz-aware ``datetime.datetime`` or :class:`Timestamp` into the :class:`Timestamp` constructor with the ``tz`` argument now raises a ``ValueError`` (:issue:`23621`)
469470
- Removed the previously deprecated :attr:`Series.base`, :attr:`Index.base`, :attr:`Categorical.base`, :attr:`Series.flags`, :attr:`Index.flags`, :attr:`PeriodArray.flags`, :attr:`Series.strides`, :attr:`Index.strides`, :attr:`Series.itemsize`, :attr:`Index.itemsize`, :attr:`Series.data`, :attr:`Index.data` (:issue:`20721`)
470471
- Changed :meth:`Timedelta.resolution` to match the behavior of the standard library ``datetime.timedelta.resolution``, for the old behavior, use :meth:`Timedelta.resolution_string` (:issue:`26839`)
471472
- Removed previously deprecated :attr:`Timestamp.weekday_name`, :attr:`DatetimeIndex.weekday_name`, and :attr:`Series.dt.weekday_name` (:issue:`18164`)

pandas/_libs/tslibs/timestamps.pyx

+2-3
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,8 @@ class Timestamp(_Timestamp):
401401
freq = None
402402

403403
if getattr(ts_input, 'tzinfo', None) is not None and tz is not None:
404-
warnings.warn("Passing a datetime or Timestamp with tzinfo and the"
405-
" tz parameter will raise in the future. Use"
406-
" tz_convert instead.", FutureWarning)
404+
raise ValueError("Cannot pass a datetime or Timestamp with tzinfo with the"
405+
" tz parameter. Use tz_convert instead.")
407406

408407
ts = convert_to_tsobject(ts_input, tz, unit, 0, 0, nanosecond or 0)
409408

pandas/tests/scalar/timestamp/test_timestamp.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -675,11 +675,13 @@ def test_constructor_invalid_frequency(self):
675675
Timestamp("2012-01-01", freq=[])
676676

677677
@pytest.mark.parametrize("box", [datetime, Timestamp])
678-
def test_depreciate_tz_and_tzinfo_in_datetime_input(self, box):
678+
def test_raise_tz_and_tzinfo_in_datetime_input(self, box):
679679
# GH 23579
680680
kwargs = {"year": 2018, "month": 1, "day": 1, "tzinfo": utc}
681-
with tm.assert_produces_warning(FutureWarning):
681+
with pytest.raises(ValueError, match="Cannot pass a datetime or Timestamp"):
682682
Timestamp(box(**kwargs), tz="US/Pacific")
683+
with pytest.raises(ValueError, match="Cannot pass a datetime or Timestamp"):
684+
Timestamp(box(**kwargs), tzinfo=pytz.timezone("US/Pacific"))
683685

684686
def test_dont_convert_dateutil_utc_to_pytz_utc(self):
685687
result = Timestamp(datetime(2018, 1, 1), tz=tzutc())

0 commit comments

Comments
 (0)