From 3639fd71543ba6ba75f79f9984d03fd364dc80f9 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Wed, 19 Mar 2025 21:35:06 -0400 Subject: [PATCH 01/11] Added deprecation warning to Timestamp constructor --- pandas/_libs/tslibs/timestamps.pyx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 23197b9a55afc..b7ac52838d5fc 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -2635,6 +2635,14 @@ class Timestamp(_Timestamp): elif not (999 >= nanosecond >= 0): raise ValueError("nanosecond must be in 0..999") + 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 + ) + ts = convert_to_tsobject(ts_input, tzobj, unit, 0, 0, nanosecond) if ts.value == NPY_NAT: From 951ffb5b13709a26c5ea2d635941ecf10038ac77 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Wed, 19 Mar 2025 23:42:39 -0400 Subject: [PATCH 02/11] Added warning filters to relevant tests --- pandas/tests/indexing/test_loc.py | 7 ++++++- pandas/tests/io/formats/test_to_csv.py | 1 + pandas/tests/scalar/timestamp/test_constructors.py | 1 + pandas/tests/test_multilevel.py | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 8838fc7eed2f7..29bd5320a6319 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2067,7 +2067,12 @@ 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:empty string to Timestamp is deprecated", + ] + ) def test_loc_setitem_with_expansion_nonunique_index(self, index): # GH#40096 if not len(index): diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 6d762fdeb8d79..659565e928001 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -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:empty string to Timestamp is deprecated") 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")) diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 2c97c4a32e0aa..f4d8da5873dfd 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -1078,6 +1078,7 @@ def test_non_nano_value(): assert result == -52700112000 +@pytest.mark.filterwarnings("ignore:empty string to Timestamp is deprecated") @pytest.mark.parametrize("na_value", [None, np.nan, np.datetime64("NaT"), NaT, NA]) def test_timestamp_constructor_na_value(na_value): # GH45481 diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index a23e6d9b3973a..aa195077de1a4 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -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:empty string to Timestamp is deprecated") def test_multiindex_dt_with_nan(self): # GH#60388 df = DataFrame( From 9ff88717fa26b46dbdfe2896875d43592c199877 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Wed, 19 Mar 2025 23:58:37 -0400 Subject: [PATCH 03/11] Corrected message matching in filterwarnings --- pandas/tests/indexing/test_loc.py | 2 +- pandas/tests/io/formats/test_to_csv.py | 2 +- pandas/tests/scalar/timestamp/test_constructors.py | 2 +- pandas/tests/test_multilevel.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 29bd5320a6319..bc90e0039ccda 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2070,7 +2070,7 @@ def test_loc_setitem_with_expansion_inf_upcast_empty(self): @pytest.mark.filterwarnings( [ "ignore:indexing past lexsort depth", - "ignore:empty string to Timestamp is deprecated", + "ignore:Passing an empty string to Timestamp", ] ) def test_loc_setitem_with_expansion_nonunique_index(self, index): diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 659565e928001..1a0c8252348ce 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -297,7 +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:empty string to Timestamp is deprecated") + @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")) diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index f4d8da5873dfd..00944c45b7e24 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -1078,7 +1078,7 @@ def test_non_nano_value(): assert result == -52700112000 -@pytest.mark.filterwarnings("ignore:empty string to Timestamp is deprecated") +@pytest.mark.filterwarnings("ignore:Passing an empty string to Timestamp") @pytest.mark.parametrize("na_value", [None, np.nan, np.datetime64("NaT"), NaT, NA]) def test_timestamp_constructor_na_value(na_value): # GH45481 diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index aa195077de1a4..d64a1ec7496a2 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -295,7 +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:empty string to Timestamp is deprecated") + @pytest.mark.filterwarnings("ignore:Passing an empty string to Timestamp") def test_multiindex_dt_with_nan(self): # GH#60388 df = DataFrame( From 4d462062a4daf8a0f592558c4a9d09911a028348 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Thu, 20 Mar 2025 03:06:47 -0400 Subject: [PATCH 04/11] fixed input to filterwarnings in test_loc.py --- pandas/tests/indexing/test_loc.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index bc90e0039ccda..b826d6551e18e 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2068,10 +2068,8 @@ def test_loc_setitem_with_expansion_inf_upcast_empty(self): tm.assert_index_equal(result, expected) @pytest.mark.filterwarnings( - [ - "ignore:indexing past lexsort depth", - "ignore:Passing an empty string to Timestamp", - ] + "ignore:indexing past lexsort depth", + "ignore:Passing an empty string to Timestamp", ) def test_loc_setitem_with_expansion_nonunique_index(self, index): # GH#40096 From bd4f28645d720db9a2972bd31091ef315ee2d43a Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Thu, 20 Mar 2025 03:50:54 -0400 Subject: [PATCH 05/11] Changed position of empty string warning --- pandas/_libs/tslibs/timestamps.pyx | 16 ++++++++-------- .../tests/scalar/timestamp/test_constructors.py | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index b7ac52838d5fc..65849c715feb9 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -2635,14 +2635,6 @@ class Timestamp(_Timestamp): elif not (999 >= nanosecond >= 0): raise ValueError("nanosecond must be in 0..999") - 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 - ) - ts = convert_to_tsobject(ts_input, tzobj, unit, 0, 0, nanosecond) if ts.value == NPY_NAT: @@ -2653,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"): diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 00944c45b7e24..2c97c4a32e0aa 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -1078,7 +1078,6 @@ def test_non_nano_value(): assert result == -52700112000 -@pytest.mark.filterwarnings("ignore:Passing an empty string to Timestamp") @pytest.mark.parametrize("na_value", [None, np.nan, np.datetime64("NaT"), NaT, NA]) def test_timestamp_constructor_na_value(na_value): # GH45481 From cbbeae105dc74f16a970658794a2ad5faf1eac40 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Sun, 30 Mar 2025 18:25:05 -0400 Subject: [PATCH 06/11] Remove ignores and test warning --- doc/source/whatsnew/v3.0.0.rst | 1 + pandas/tests/indexing/test_loc.py | 5 +---- pandas/tests/io/formats/test_to_csv.py | 1 - pandas/tests/scalar/timestamp/test_constructors.py | 5 +++++ pandas/tests/test_multilevel.py | 1 - 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index b4aa6447c0a1b..eb5abbd0bc8b2 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -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`) diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index b826d6551e18e..8838fc7eed2f7 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -2067,10 +2067,7 @@ 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", - "ignore:Passing an empty string to Timestamp", - ) + @pytest.mark.filterwarnings("ignore:indexing past lexsort depth") def test_loc_setitem_with_expansion_nonunique_index(self, index): # GH#40096 if not len(index): diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 1a0c8252348ce..6d762fdeb8d79 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -297,7 +297,6 @@ 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")) diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index 2c97c4a32e0aa..ffee92a3e95ba 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -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(DeprecationWarning, match=msg): + Timestamp("") + @pytest.mark.parametrize( "value, check_kwargs", [ diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index d64a1ec7496a2..a23e6d9b3973a 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -295,7 +295,6 @@ 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( From 32242c0a6891d5c6209a86b0851198f8da458739 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Sun, 30 Mar 2025 20:03:33 -0400 Subject: [PATCH 07/11] Changed DeprecationWarning to FutureWarning --- pandas/tests/scalar/timestamp/test_constructors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/scalar/timestamp/test_constructors.py b/pandas/tests/scalar/timestamp/test_constructors.py index ffee92a3e95ba..d7721b008ccad 100644 --- a/pandas/tests/scalar/timestamp/test_constructors.py +++ b/pandas/tests/scalar/timestamp/test_constructors.py @@ -64,7 +64,7 @@ def test_constructor_float_not_round_with_YM_unit_raises(self): def test_constructor_with_empty_string(self): msg = "Passing an empty string to Timestamp" - with tm.assert_produces_warning(DeprecationWarning, match=msg): + with tm.assert_produces_warning(FutureWarning, match=msg): Timestamp("") @pytest.mark.parametrize( From fe341cf146c80bb409ec2f169301c86a1b4db832 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Thu, 3 Apr 2025 08:40:27 -0400 Subject: [PATCH 08/11] Moved warning where str is checked --- pandas/_libs/tslibs/timestamps.pyx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 65849c715feb9..fb145d3d646b6 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -2587,6 +2587,14 @@ class Timestamp(_Timestamp): tzinfo is None): return ts_input elif isinstance(ts_input, str): + 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 + ) + # User passed a date string to parse. # Check that the user didn't also pass a date attribute kwarg. if any(arg is not None for arg in _date_attributes): @@ -2645,14 +2653,6 @@ 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"): From 3eb2271a3ae8c18f4e0f02163bc1bb1440c7db95 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Sat, 5 Apr 2025 11:31:48 -0400 Subject: [PATCH 09/11] asserted FutureWarning in relevant tests --- pandas/_libs/tslibs/timestamps.pyx | 2 +- pandas/tests/indexing/test_loc.py | 40 ++++++++++++++++++++++---- pandas/tests/io/formats/test_to_csv.py | 8 ++++-- pandas/tests/test_multilevel.py | 4 ++- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index fb145d3d646b6..9c56f96fc138b 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -2592,7 +2592,7 @@ class Timestamp(_Timestamp): "Passing an empty string to Timestamp is deprecated and will raise " "a ValueError in a future version.", FutureWarning, - stacklevel = 2 + stacklevel = find_stack_level() ) # User passed a date string to parse. diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index 8838fc7eed2f7..aea75d29e361e 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -39,7 +39,10 @@ to_timedelta, ) import pandas._testing as tm -from pandas.api.types import is_scalar +from pandas.api.types import ( + is_datetime64_any_dtype, + is_scalar, +) from pandas.core.indexing import _one_ellipsis_message from pandas.tests.indexing.common import check_indexing_smoketest_or_raises @@ -2084,7 +2087,21 @@ def test_loc_setitem_with_expansion_nonunique_index(self, index): assert key not in index # otherwise test is invalid # TODO: using a tuple key breaks here in many cases - exp_index = index.insert(len(index), key) + msg = "Passing an empty string to Timestamp" + contains_datetime = False + if isinstance(index, MultiIndex): + for i in range(index.nlevels): + if is_datetime64_any_dtype(index.get_level_values(i)): + contains_datetime = True + break + if contains_datetime: + with tm.assert_produces_warning(FutureWarning, match=msg): + exp_index = index.insert(len(index), key) + else: + exp_index = index.insert(len(index), key) + else: + exp_index = index.insert(len(index), key) + if isinstance(index, MultiIndex): assert exp_index[-1][0] == key else: @@ -2094,19 +2111,32 @@ def test_loc_setitem_with_expansion_nonunique_index(self, index): # Add new row, but no new columns df = orig.copy() - df.loc[key, 0] = N + if contains_datetime: + with tm.assert_produces_warning(FutureWarning, match=msg): + df.loc[key, 0] = N + else: + df.loc[key, 0] = N tm.assert_frame_equal(df, expected) # add new row on a Series ser = orig.copy()[0] - ser.loc[key] = N + if contains_datetime: + with tm.assert_produces_warning(FutureWarning, match=msg): + ser.loc[key] = N + else: + ser.loc[key] = N + tm.assert_frame_equal(df, expected) # the series machinery lets us preserve int dtype instead of float expected = expected[0].astype(np.int64) tm.assert_series_equal(ser, expected) # add new row and new column df = orig.copy() - df.loc[key, 1] = N + if contains_datetime: + with tm.assert_produces_warning(FutureWarning, match=msg): + df.loc[key, 1] = N + else: + df.loc[key, 1] = N expected = DataFrame( {0: list(arr) + [np.nan], 1: [np.nan] * N + [float(N)]}, index=exp_index, diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 6d762fdeb8d79..d38387e523da9 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -302,7 +302,9 @@ def test_to_csv_date_format_in_categorical(self): ser = pd.Series(pd.to_datetime(["2021-03-27", pd.NaT], format="%Y-%m-%d")) ser = ser.astype("category") expected = tm.convert_rows_list_to_csv_str(["0", "2021-03-27", '""']) - assert ser.to_csv(index=False) == expected + msg = "Passing an empty string to Timestamp" + with tm.assert_produces_warning(FutureWarning, match=msg): + assert ser.to_csv(index=False) == expected ser = pd.Series( pd.date_range( @@ -310,7 +312,9 @@ def test_to_csv_date_format_in_categorical(self): ).append(pd.DatetimeIndex([pd.NaT])) ) ser = ser.astype("category") - assert ser.to_csv(index=False, date_format="%Y-%m-%d") == expected + msg = "Passing an empty string to Timestamp" + with tm.assert_produces_warning(FutureWarning, match=msg): + assert ser.to_csv(index=False, date_format="%Y-%m-%d") == expected def test_to_csv_float_ea_float_format(self): # GH#45991 diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index a23e6d9b3973a..321a68cad2f38 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -313,7 +313,9 @@ def test_multiindex_dt_with_nan(self): names=[None, "Date"], ), ) - df = df.reset_index() + msg = "Passing an empty string to Timestamp" + with tm.assert_produces_warning(FutureWarning, match=msg): + df = df.reset_index() result = df[df.columns[0]] expected = Series(["a", "b", "c", "d"], name=("sub", np.nan)) tm.assert_series_equal(result, expected) From 6d81c60659826b620db195f800f40ce6ced708e1 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Sat, 5 Apr 2025 12:25:43 -0400 Subject: [PATCH 10/11] asserted warning for test_nat.py --- pandas/tests/scalar/test_nat.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index b20df43dd49a6..753745aac6128 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -109,7 +109,13 @@ def test_nat_vector_field_access(): "value", [None, np.nan, iNaT, float("nan"), NaT, "NaT", "nat", "", "NAT"] ) def test_identity(klass, value): - assert klass(value) is NaT + if value == "": + msg = "Passing an empty string to Timestamp" + with tm.assert_produces_warning(FutureWarning, match=msg): + result = klass(value) + else: + result = klass(value) + assert result is NaT @pytest.mark.parametrize("klass", [Timestamp, Timedelta]) From b9f2aefe34f55fd4b655e87be78528d83c7dfb07 Mon Sep 17 00:00:00 2001 From: John Hendricks Date: Sat, 5 Apr 2025 18:45:02 -0400 Subject: [PATCH 11/11] add condition to test_identity --- pandas/tests/scalar/test_nat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index 753745aac6128..c274670e2acdc 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -109,7 +109,7 @@ def test_nat_vector_field_access(): "value", [None, np.nan, iNaT, float("nan"), NaT, "NaT", "nat", "", "NAT"] ) def test_identity(klass, value): - if value == "": + if value == "" and klass == Timestamp: msg = "Passing an empty string to Timestamp" with tm.assert_produces_warning(FutureWarning, match=msg): result = klass(value)