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 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
8 changes: 8 additions & 0 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/indexing/test_loc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,10 @@ def test_loc_setitem_with_expansion_inf_upcast_empty(self):
expected = Index([0, 1, np.inf], dtype=np.float64)
tm.assert_index_equal(result, expected)

@pytest.mark.filterwarnings("ignore:indexing past lexsort depth")
@pytest.mark.filterwarnings(
"ignore:indexing past lexsort depth",
"ignore:Passing an empty string to Timestamp",
Copy link
Member

Choose a reason for hiding this comment

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

Instead of ignoring in each of these tests, can you test the warning. See

https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#testing-a-warning

Copy link
Member

Choose a reason for hiding this comment

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

@jhendricks487 - you still need to modify the other tests where this warning occurs with tm.assert_produces_warning. Any warning that occurs outside of such a block will result in the test failing.

)
def test_loc_setitem_with_expansion_nonunique_index(self, index):
# GH#40096
if not len(index):
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/io/formats/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def test_to_csv_different_datetime_formats(self):
expected = tm.convert_rows_list_to_csv_str(expected_rows)
assert df.to_csv(index=False) == expected

@pytest.mark.filterwarnings("ignore:Passing an empty string to Timestamp")
def test_to_csv_date_format_in_categorical(self):
# GH#40754
ser = pd.Series(pd.to_datetime(["2021-03-27", pd.NaT], format="%Y-%m-%d"))
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/test_multilevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def test_multiindex_insert_level_with_na(self, na):
df[na, "B"] = 1
tm.assert_frame_equal(df[na], DataFrame([1], columns=["B"]))

@pytest.mark.filterwarnings("ignore:Passing an empty string to Timestamp")
def test_multiindex_dt_with_nan(self):
# GH#60388
df = DataFrame(
Expand Down
Loading