Skip to content
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

DEPR: tz_convert in the Timestamp constructor raises #29929

Merged
merged 5 commits into from
Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,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`)
- 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`)
- Removed previously deprecated ``errors`` argument in :meth:`Timestamp.tz_localize`, :meth:`DatetimeIndex.tz_localize`, and :meth:`Series.tz_localize` (:issue:`22644`)
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
5 changes: 3 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,12 @@ 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also have a case with the tzinfo kwarg

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we need separate pytest.raises contexts (and the tzinfo kwarg is supposed to be a tzinfo object)

Timestamp(box(**kwargs), tzinfo="US/Pacific")

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