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

BUG: Added deprecation warning to Timestamp constructor #61149

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
@@ -416,6 +416,7 @@ Other Deprecations
- Deprecated allowing non-keyword arguments in :meth:`Series.to_string` except ``buf``. (:issue:`57280`)
- Deprecated behavior of :meth:`.DataFrameGroupBy.groups` and :meth:`.SeriesGroupBy.groups`, in a future version ``groups`` by one element list will return tuple instead of scalar. (:issue:`58858`)
- Deprecated behavior of :meth:`Series.dt.to_pytimedelta`, in a future version this will return a :class:`Series` containing python ``datetime.timedelta`` objects instead of an ``ndarray`` of timedelta; this matches the behavior of other :meth:`Series.dt` properties. (:issue:`57463`)
- Deprecated empty string in :class:`Timestamp` (:issue:`61149`)
- Deprecated lowercase strings ``d``, ``b`` and ``c`` denoting frequencies in :class:`Day`, :class:`BusinessDay` and :class:`CustomBusinessDay` in favour of ``D``, ``B`` and ``C`` (:issue:`58998`)
- Deprecated lowercase strings ``w``, ``w-mon``, ``w-tue``, etc. denoting frequencies in :class:`Week` in favour of ``W``, ``W-MON``, ``W-TUE``, etc. (:issue:`58998`)
- Deprecated parameter ``method`` in :meth:`DataFrame.reindex_like` / :meth:`Series.reindex_like` (:issue:`58667`)
8 changes: 8 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
@@ -2645,6 +2645,14 @@ class Timestamp(_Timestamp):
"Passed data is timezone-aware, incompatible with 'tz=None'."
)

if ts_input == "":
warnings.warn(
"Passing an empty string to Timestamp is deprecated and will raise "
"a ValueError in a future version.",
FutureWarning,
stacklevel = 2
)

return create_timestamp_from_ts(ts.value, ts.dts, ts.tzinfo, ts.fold, ts.creso)

def _round(self, freq, mode, ambiguous="raise", nonexistent="raise"):
5 changes: 5 additions & 0 deletions pandas/tests/scalar/timestamp/test_constructors.py
Original file line number Diff line number Diff line change
@@ -62,6 +62,11 @@ def test_constructor_float_not_round_with_YM_unit_raises(self):
with pytest.raises(ValueError, match=msg):
Timestamp(150.5, unit="M")

def test_constructor_with_empty_string(self):
msg = "Passing an empty string to Timestamp"
with tm.assert_produces_warning(FutureWarning, match=msg):
Timestamp("")

@pytest.mark.parametrize(
"value, check_kwargs",
[
Loading
Oops, something went wrong.