From 8f7432b1cc7791c2ccbb003aa4206c24476b333d Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Mon, 5 Sep 2022 16:44:42 +0200 Subject: [PATCH 01/19] WARN: Remove false positive warning for iloc inplaceness --- pandas/core/indexing.py | 3 +++ pandas/tests/frame/indexing/test_indexing.py | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 0fb499088868a..dfd585f4e13f7 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -32,6 +32,7 @@ is_array_like, is_bool_dtype, is_extension_array_dtype, + is_float_dtype, is_hashable, is_integer, is_iterator, @@ -2016,6 +2017,8 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): and ( np.shares_memory(new_values, orig_values) or new_values.shape != orig_values.shape + or not is_float_dtype(orig_values) + and isna(new_values).any() ) ): # TODO: get something like tm.shares_memory working? diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 65ac5e2c2bd1e..7f84d8a367eac 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -1326,7 +1326,8 @@ def test_loc_expand_empty_frame_keep_midx_names(self): def test_loc_setitem_rhs_frame(self, idxr, val): # GH#47578 df = DataFrame({"a": [1, 2]}) - df.loc[:, "a"] = DataFrame({"a": [val, 11]}, index=[1, 2]) + with tm.assert_produces_warning(None): + df.loc[:, idxr] = DataFrame({"a": [val, 11]}, index=[1, 2]) expected = DataFrame({"a": [np.nan, val]}) tm.assert_frame_equal(df, expected) From 9ac855bcdb37609685b2017a6bda756e6c6e5b7c Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Mon, 5 Sep 2022 16:47:18 +0200 Subject: [PATCH 02/19] Improve check --- pandas/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index dfd585f4e13f7..d2eddba6f5798 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2018,7 +2018,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): np.shares_memory(new_values, orig_values) or new_values.shape != orig_values.shape or not is_float_dtype(orig_values) - and isna(new_values).any() + and is_float_dtype(new_values) ) ): # TODO: get something like tm.shares_memory working? From 2c3920c8496d90cce7b215b087e0d2a642b9a021 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Mon, 5 Sep 2022 16:48:07 +0200 Subject: [PATCH 03/19] Improve check --- pandas/core/indexing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index d2eddba6f5798..dfd585f4e13f7 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2018,7 +2018,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): np.shares_memory(new_values, orig_values) or new_values.shape != orig_values.shape or not is_float_dtype(orig_values) - and is_float_dtype(new_values) + and isna(new_values).any() ) ): # TODO: get something like tm.shares_memory working? From 8fc58f312c63a239a4c41d89a2966ef0cc20ce5d Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Mon, 5 Sep 2022 17:32:04 +0200 Subject: [PATCH 04/19] Check for object too --- pandas/core/indexing.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index dfd585f4e13f7..3a292d6820698 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2018,6 +2018,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): np.shares_memory(new_values, orig_values) or new_values.shape != orig_values.shape or not is_float_dtype(orig_values) + and not is_object_dtype(orig_values) and isna(new_values).any() ) ): From ab1080c42f2c0fbd5226af45add30dce23820852 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Mon, 5 Sep 2022 17:48:41 +0200 Subject: [PATCH 05/19] Improve check --- pandas/core/indexing.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 3a292d6820698..2503a7d70b960 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -32,7 +32,6 @@ is_array_like, is_bool_dtype, is_extension_array_dtype, - is_float_dtype, is_hashable, is_integer, is_iterator, @@ -2017,8 +2016,7 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): and ( np.shares_memory(new_values, orig_values) or new_values.shape != orig_values.shape - or not is_float_dtype(orig_values) - and not is_object_dtype(orig_values) + or not can_hold_element(orig_values, np.nan) and isna(new_values).any() ) ): From 40427c41efb3e9c224580916a7e5dccd19863802 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Mon, 5 Sep 2022 23:39:58 +0200 Subject: [PATCH 06/19] Fix test --- pandas/tests/frame/indexing/test_indexing.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index 7f84d8a367eac..d11d7b607aded 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -9,6 +9,7 @@ import pytest from pandas._libs import iNaT +from pandas.compat import is_numpy_dev from pandas.errors import ( InvalidIndexError, SettingWithCopyError, @@ -1326,8 +1327,12 @@ def test_loc_expand_empty_frame_keep_midx_names(self): def test_loc_setitem_rhs_frame(self, idxr, val): # GH#47578 df = DataFrame({"a": [1, 2]}) - with tm.assert_produces_warning(None): - df.loc[:, idxr] = DataFrame({"a": [val, 11]}, index=[1, 2]) + if is_numpy_dev: + with tm.assert_produces_warning(RuntimeWarning): + df.loc[:, idxr] = DataFrame({"a": [val, 11]}, index=[1, 2]) + else: + with tm.assert_produces_warning(None): + df.loc[:, idxr] = DataFrame({"a": [val, 11]}, index=[1, 2]) expected = DataFrame({"a": [np.nan, val]}) tm.assert_frame_equal(df, expected) From 724089562b28b17c8c80cd7dec217a05504df0a7 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 6 Sep 2022 11:05:34 +0200 Subject: [PATCH 07/19] Filter warning --- pandas/core/dtypes/cast.py | 3 ++- pandas/tests/frame/indexing/test_indexing.py | 9 ++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 4244217da7865..6812bd1196284 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1970,7 +1970,8 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any: if tipo.kind not in ["i", "u"]: if isinstance(element, np.ndarray) and element.dtype.kind == "f": # If all can be losslessly cast to integers, then we can hold them - casted = element.astype(dtype) + with np.errstate(invalid="ignore"): + casted = element.astype(dtype) comp = casted == element if comp.all(): # Return the casted values bc they can be passed to diff --git a/pandas/tests/frame/indexing/test_indexing.py b/pandas/tests/frame/indexing/test_indexing.py index d11d7b607aded..7f84d8a367eac 100644 --- a/pandas/tests/frame/indexing/test_indexing.py +++ b/pandas/tests/frame/indexing/test_indexing.py @@ -9,7 +9,6 @@ import pytest from pandas._libs import iNaT -from pandas.compat import is_numpy_dev from pandas.errors import ( InvalidIndexError, SettingWithCopyError, @@ -1327,12 +1326,8 @@ def test_loc_expand_empty_frame_keep_midx_names(self): def test_loc_setitem_rhs_frame(self, idxr, val): # GH#47578 df = DataFrame({"a": [1, 2]}) - if is_numpy_dev: - with tm.assert_produces_warning(RuntimeWarning): - df.loc[:, idxr] = DataFrame({"a": [val, 11]}, index=[1, 2]) - else: - with tm.assert_produces_warning(None): - df.loc[:, idxr] = DataFrame({"a": [val, 11]}, index=[1, 2]) + with tm.assert_produces_warning(None): + df.loc[:, idxr] = DataFrame({"a": [val, 11]}, index=[1, 2]) expected = DataFrame({"a": [np.nan, val]}) tm.assert_frame_equal(df, expected) From a1a824c2987ab0eee909448d4e3833f5dce52fdf Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 6 Sep 2022 11:06:46 +0200 Subject: [PATCH 08/19] Add another filter --- pandas/_testing/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/_testing/__init__.py b/pandas/_testing/__init__.py index 1035fd08a1a36..c15e597558221 100644 --- a/pandas/_testing/__init__.py +++ b/pandas/_testing/__init__.py @@ -459,7 +459,8 @@ def all_timeseries_index_generator(k: int = 10) -> Iterable[Index]: def make_rand_series(name=None, dtype=np.float64) -> Series: index = makeStringIndex(_N) data = np.random.randn(_N) - data = data.astype(dtype, copy=False) + with np.errstate(invalid="ignore"): + data = data.astype(dtype, copy=False) return Series(data, index=index, name=name) From 03bc147d9227dda70607b522ba13332556d3d02d Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 6 Sep 2022 22:37:09 +0200 Subject: [PATCH 09/19] Add comment --- pandas/core/dtypes/cast.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 6812bd1196284..ceb3d16949f91 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1971,6 +1971,8 @@ def np_can_hold_element(dtype: np.dtype, element: Any) -> Any: if isinstance(element, np.ndarray) and element.dtype.kind == "f": # If all can be losslessly cast to integers, then we can hold them with np.errstate(invalid="ignore"): + # We check afterwards if cast was losslessly, so no need to show + # the warning casted = element.astype(dtype) comp = casted == element if comp.all(): From 44e910d81736b6328919f7752db44e203c7a3646 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 6 Sep 2022 22:41:24 +0200 Subject: [PATCH 10/19] Add parens --- pandas/core/indexing.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 2503a7d70b960..a191e69014302 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2016,8 +2016,10 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): and ( np.shares_memory(new_values, orig_values) or new_values.shape != orig_values.shape - or not can_hold_element(orig_values, np.nan) - and isna(new_values).any() + or ( + not can_hold_element(orig_values, np.nan) + and isna(new_values).any() + ) ) ): # TODO: get something like tm.shares_memory working? From 0d2c2c488f4e64b62c6da52565ae858547062c61 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Thu, 8 Sep 2022 20:39:01 +0200 Subject: [PATCH 11/19] Recheck --- pandas/core/indexing.py | 10 ++++++---- pandas/tests/frame/methods/test_diff.py | 7 +++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index a191e69014302..a999396c28a05 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2010,16 +2010,18 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): if warn: new_values = self.obj._get_column_array(loc) + # Check again, iset_item might have introduced nans through reindexing + warn = can_hold_element(orig_values, new_values) + + if not warn: + return + if ( isinstance(new_values, np.ndarray) and isinstance(orig_values, np.ndarray) and ( np.shares_memory(new_values, orig_values) or new_values.shape != orig_values.shape - or ( - not can_hold_element(orig_values, np.nan) - and isna(new_values).any() - ) ) ): # TODO: get something like tm.shares_memory working? diff --git a/pandas/tests/frame/methods/test_diff.py b/pandas/tests/frame/methods/test_diff.py index fc804836f9a9b..92b6310657220 100644 --- a/pandas/tests/frame/methods/test_diff.py +++ b/pandas/tests/frame/methods/test_diff.py @@ -91,8 +91,11 @@ def test_diff_datetime_with_nat_zero_periods(self, tz): df[1] = ser.copy() - msg = "will attempt to set the values inplace instead" - with tm.assert_produces_warning(FutureWarning, match=msg): + if tz is None: + msg = "will attempt to set the values inplace instead" + with tm.assert_produces_warning(FutureWarning, match=msg): + df.iloc[:, 0] = pd.NaT + else: df.iloc[:, 0] = pd.NaT expected = df - df From 7f04bdca880065a0722e58f3a0df8ffd118fadf7 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Thu, 8 Sep 2022 21:07:32 +0200 Subject: [PATCH 12/19] Only check new values --- pandas/core/indexing.py | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index a999396c28a05..85c61f40c023a 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1994,27 +1994,16 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): self.obj._clear_item_cache() return + self.obj._iset_item(loc, value) + # We will not operate in-place, but will attempt to in the future. # To determine whether we need to issue a FutureWarning, see if the # setting in-place would work, i.e. behavior will change. - if isinstance(value, ABCSeries): - warn = can_hold_element(orig_values, value._values) - else: - warn = can_hold_element(orig_values, value) - - # Don't issue the warning yet, as we can still trim a few cases where - # behavior will not change. - self.obj._iset_item(loc, value) + new_values = self.obj._get_column_array(loc) + warn = can_hold_element(orig_values, new_values) if warn: - new_values = self.obj._get_column_array(loc) - - # Check again, iset_item might have introduced nans through reindexing - warn = can_hold_element(orig_values, new_values) - - if not warn: - return if ( isinstance(new_values, np.ndarray) From c4b07800f38b239fe8ad45f888468483323b3843 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Thu, 8 Sep 2022 21:08:04 +0200 Subject: [PATCH 13/19] Add comment --- pandas/core/indexing.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 85c61f40c023a..4d22bbd93e494 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2003,6 +2003,9 @@ def _setitem_single_column(self, loc: int, value, plane_indexer): new_values = self.obj._get_column_array(loc) warn = can_hold_element(orig_values, new_values) + # Don't issue the warning yet, as we can still trim a few cases where + # behavior will not change. + if warn: if ( From 49da3ce3be40cda74c80936041eb0e8064b2a003 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Thu, 8 Sep 2022 21:09:47 +0200 Subject: [PATCH 14/19] Check for now warning --- pandas/tests/frame/methods/test_diff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_diff.py b/pandas/tests/frame/methods/test_diff.py index 92b6310657220..fe512eff75b7c 100644 --- a/pandas/tests/frame/methods/test_diff.py +++ b/pandas/tests/frame/methods/test_diff.py @@ -96,7 +96,8 @@ def test_diff_datetime_with_nat_zero_periods(self, tz): with tm.assert_produces_warning(FutureWarning, match=msg): df.iloc[:, 0] = pd.NaT else: - df.iloc[:, 0] = pd.NaT + with tm.assert_produces_warning(None): + df.iloc[:, 0] = pd.NaT expected = df - df assert expected[0].isna().all() From 805ec5dd907465856fc7e8d42dfeec86fcfdc115 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Mon, 12 Sep 2022 19:35:56 +0200 Subject: [PATCH 15/19] Refactor --- pandas/core/indexing.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 947fc9fbef330..2c127d79379d5 100644 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -2001,12 +2001,10 @@ def _setitem_single_column(self, loc: int, value, plane_indexer) -> None: # setting in-place would work, i.e. behavior will change. new_values = self.obj._get_column_array(loc) - warn = can_hold_element(orig_values, new_values) - # Don't issue the warning yet, as we can still trim a few cases where - # behavior will not change. - - if warn: + if can_hold_element(orig_values, new_values): + # Don't issue the warning yet, as we can still trim a few cases where + # behavior will not change. if ( isinstance(new_values, np.ndarray) From 7762cdad26c8f75d47073b73dc79073ccae5c229 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 13 Sep 2022 10:25:16 +0200 Subject: [PATCH 16/19] Make test consistent --- pandas/tests/frame/test_nonunique_indexes.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pandas/tests/frame/test_nonunique_indexes.py b/pandas/tests/frame/test_nonunique_indexes.py index cd6397b053803..96838c5fcb4d4 100644 --- a/pandas/tests/frame/test_nonunique_indexes.py +++ b/pandas/tests/frame/test_nonunique_indexes.py @@ -318,16 +318,13 @@ def test_dup_columns_across_dtype(self): xp.columns = ["A", "A", "B"] tm.assert_frame_equal(rs, xp) - def test_set_value_by_index(self, using_array_manager): + def test_set_value_by_index(self): # See gh-12344 - warn = FutureWarning if using_array_manager else None - msg = "will attempt to set the values inplace" - df = DataFrame(np.arange(9).reshape(3, 3).T) df.columns = list("AAA") expected = df.iloc[:, 2] - with tm.assert_produces_warning(warn, match=msg): + with tm.assert_produces_warning(None): df.iloc[:, 0] = 3 tm.assert_series_equal(df.iloc[:, 2], expected) @@ -335,6 +332,6 @@ def test_set_value_by_index(self, using_array_manager): df.columns = [2, float(2), str(2)] expected = df.iloc[:, 1] - with tm.assert_produces_warning(warn, match=msg): + with tm.assert_produces_warning(None): df.iloc[:, 0] = 3 tm.assert_series_equal(df.iloc[:, 1], expected) From ead315a28c8c4247f2cc19bc67c794c81612e1d5 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 13 Sep 2022 11:25:19 +0200 Subject: [PATCH 17/19] Revert "Make test consistent" This reverts commit 7762cdad26c8f75d47073b73dc79073ccae5c229. --- pandas/tests/frame/test_nonunique_indexes.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/tests/frame/test_nonunique_indexes.py b/pandas/tests/frame/test_nonunique_indexes.py index 96838c5fcb4d4..cd6397b053803 100644 --- a/pandas/tests/frame/test_nonunique_indexes.py +++ b/pandas/tests/frame/test_nonunique_indexes.py @@ -318,13 +318,16 @@ def test_dup_columns_across_dtype(self): xp.columns = ["A", "A", "B"] tm.assert_frame_equal(rs, xp) - def test_set_value_by_index(self): + def test_set_value_by_index(self, using_array_manager): # See gh-12344 + warn = FutureWarning if using_array_manager else None + msg = "will attempt to set the values inplace" + df = DataFrame(np.arange(9).reshape(3, 3).T) df.columns = list("AAA") expected = df.iloc[:, 2] - with tm.assert_produces_warning(None): + with tm.assert_produces_warning(warn, match=msg): df.iloc[:, 0] = 3 tm.assert_series_equal(df.iloc[:, 2], expected) @@ -332,6 +335,6 @@ def test_set_value_by_index(self): df.columns = [2, float(2), str(2)] expected = df.iloc[:, 1] - with tm.assert_produces_warning(None): + with tm.assert_produces_warning(warn, match=msg): df.iloc[:, 0] = 3 tm.assert_series_equal(df.iloc[:, 1], expected) From 8a772c7b7f1097cbd24359f6907116e9f043072d Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Tue, 13 Sep 2022 11:27:03 +0200 Subject: [PATCH 18/19] Fix --- pandas/tests/frame/test_nonunique_indexes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_nonunique_indexes.py b/pandas/tests/frame/test_nonunique_indexes.py index cd6397b053803..2c28800fb181f 100644 --- a/pandas/tests/frame/test_nonunique_indexes.py +++ b/pandas/tests/frame/test_nonunique_indexes.py @@ -1,6 +1,8 @@ import numpy as np import pytest +from pandas.compat import is_platform_windows + import pandas as pd from pandas import ( DataFrame, @@ -320,7 +322,9 @@ def test_dup_columns_across_dtype(self): def test_set_value_by_index(self, using_array_manager): # See gh-12344 - warn = FutureWarning if using_array_manager else None + warn = ( + FutureWarning if using_array_manager and not is_platform_windows() else None + ) msg = "will attempt to set the values inplace" df = DataFrame(np.arange(9).reshape(3, 3).T) From a6de70ef3f4aa3661d75cba7e3f74af8ac060733 Mon Sep 17 00:00:00 2001 From: Patrick Hoefler Date: Thu, 15 Sep 2022 22:40:04 +0200 Subject: [PATCH 19/19] xfail test --- pandas/tests/frame/methods/test_diff.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pandas/tests/frame/methods/test_diff.py b/pandas/tests/frame/methods/test_diff.py index fe512eff75b7c..9a9fea3462752 100644 --- a/pandas/tests/frame/methods/test_diff.py +++ b/pandas/tests/frame/methods/test_diff.py @@ -82,7 +82,7 @@ def test_diff_datetime_axis0_with_nat(self, tz): expected = Series(ex_index).to_frame() tm.assert_frame_equal(result, expected) - @pytest.mark.parametrize("tz", [None, "UTC"]) + @pytest.mark.parametrize("tz", [pytest.param(None, marks=pytest.mark.xfail), "UTC"]) def test_diff_datetime_with_nat_zero_periods(self, tz): # diff on NaT values should give NaT, not timedelta64(0) dti = date_range("2016-01-01", periods=4, tz=tz) @@ -91,13 +91,8 @@ def test_diff_datetime_with_nat_zero_periods(self, tz): df[1] = ser.copy() - if tz is None: - msg = "will attempt to set the values inplace instead" - with tm.assert_produces_warning(FutureWarning, match=msg): - df.iloc[:, 0] = pd.NaT - else: - with tm.assert_produces_warning(None): - df.iloc[:, 0] = pd.NaT + with tm.assert_produces_warning(None): + df.iloc[:, 0] = pd.NaT expected = df - df assert expected[0].isna().all()