Skip to content

Commit

Permalink
DEPR: tz_convert in the Timestamp constructor raises (pandas-dev#29929)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored and proost committed Dec 19, 2019
1 parent e7be89e commit 657c1d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ or ``matplotlib.Axes.plot``. See :ref:`plotting.formatters` for more.
- Changed the default ``fill_value`` in :meth:`Categorical.take` from ``True`` to ``False`` (:issue:`20841`)
- 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>`,
- :func:`Series.expanding().apply() <pandas.core.window.Expanding.apply>`, and :func:`DataFrame.expanding().apply() <pandas.core.window.Expanding.apply>` to ``False`` (:issue:`20584`)
- Passing a tz-aware ``datetime.datetime`` or :class:`Timestamp` into the :class:`Timestamp` constructor with the ``tz`` argument now raises a ``ValueError`` (:issue:`23621`)
- 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`)
- 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`)
- Removed previously deprecated :attr:`Timestamp.weekday_name`, :attr:`DatetimeIndex.weekday_name`, and :attr:`Series.dt.weekday_name` (:issue:`18164`)
Expand Down
5 changes: 2 additions & 3 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,8 @@ class Timestamp(_Timestamp):
freq = None

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

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

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/scalar/timestamp/test_timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,11 +675,13 @@ def test_constructor_invalid_frequency(self):
Timestamp("2012-01-01", freq=[])

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

def test_dont_convert_dateutil_utc_to_pytz_utc(self):
result = Timestamp(datetime(2018, 1, 1), tz=tzutc())
Expand Down

0 comments on commit 657c1d3

Please sign in to comment.