From cf610865da4e824d53cc0d779f1035cd46039def Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 27 Nov 2021 22:09:11 -0800 Subject: [PATCH 1/3] CI/TST: Change id to np.shares_memory for flaky tests --- pandas/tests/frame/methods/test_rename.py | 6 ++++-- pandas/tests/frame/methods/test_sort_index.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pandas/tests/frame/methods/test_rename.py b/pandas/tests/frame/methods/test_rename.py index 1581bc8a0c70b..6eca918c72928 100644 --- a/pandas/tests/frame/methods/test_rename.py +++ b/pandas/tests/frame/methods/test_rename.py @@ -184,14 +184,16 @@ def test_rename_inplace(self, float_frame): assert "C" in float_frame assert "foo" not in float_frame - c_id = id(float_frame["C"]) + c_values = float_frame["C"]._values float_frame = float_frame.copy() return_value = float_frame.rename(columns={"C": "foo"}, inplace=True) assert return_value is None assert "C" not in float_frame assert "foo" in float_frame - assert id(float_frame["foo"]) != c_id + # GH 44153 + # Used to be id(float_frame["foo"]) != c_id, but flaky in the CI + assert not np.shares_memory(float_frame["foo"]._values, c_values) def test_rename_bug(self): # GH 5344 diff --git a/pandas/tests/frame/methods/test_sort_index.py b/pandas/tests/frame/methods/test_sort_index.py index 71822628473f4..918f86c1abbb1 100644 --- a/pandas/tests/frame/methods/test_sort_index.py +++ b/pandas/tests/frame/methods/test_sort_index.py @@ -224,13 +224,15 @@ def test_sort_index_inplace(self): # axis=0 unordered = frame.loc[[3, 2, 4, 1]] - a_id = id(unordered["A"]) + a_values = unordered["A"]._values df = unordered.copy() return_value = df.sort_index(inplace=True) assert return_value is None expected = frame tm.assert_frame_equal(df, expected) - assert a_id != id(df["A"]) + # GH 44153 related + # Used to be a_id != id(df["A"]), but flaky in the CI + assert not np.shares_memory(a_values, df["A"]._values) df = unordered.copy() return_value = df.sort_index(ascending=False, inplace=True) From 8a360a6af32b0acadebd514b663858eadeb9690c Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 28 Nov 2021 09:53:55 -0800 Subject: [PATCH 2/3] Change to is --- pandas/tests/frame/methods/test_rename.py | 4 ++-- pandas/tests/frame/methods/test_sort_index.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/frame/methods/test_rename.py b/pandas/tests/frame/methods/test_rename.py index 6eca918c72928..33fb191027c27 100644 --- a/pandas/tests/frame/methods/test_rename.py +++ b/pandas/tests/frame/methods/test_rename.py @@ -184,7 +184,7 @@ def test_rename_inplace(self, float_frame): assert "C" in float_frame assert "foo" not in float_frame - c_values = float_frame["C"]._values + c_values = float_frame["C"] float_frame = float_frame.copy() return_value = float_frame.rename(columns={"C": "foo"}, inplace=True) assert return_value is None @@ -193,7 +193,7 @@ def test_rename_inplace(self, float_frame): assert "foo" in float_frame # GH 44153 # Used to be id(float_frame["foo"]) != c_id, but flaky in the CI - assert not np.shares_memory(float_frame["foo"]._values, c_values) + assert float_frame["foo"] is not c_values def test_rename_bug(self): # GH 5344 diff --git a/pandas/tests/frame/methods/test_sort_index.py b/pandas/tests/frame/methods/test_sort_index.py index 918f86c1abbb1..6e40e95e7602f 100644 --- a/pandas/tests/frame/methods/test_sort_index.py +++ b/pandas/tests/frame/methods/test_sort_index.py @@ -224,7 +224,7 @@ def test_sort_index_inplace(self): # axis=0 unordered = frame.loc[[3, 2, 4, 1]] - a_values = unordered["A"]._values + a_values = unordered["A"] df = unordered.copy() return_value = df.sort_index(inplace=True) assert return_value is None @@ -232,7 +232,7 @@ def test_sort_index_inplace(self): tm.assert_frame_equal(df, expected) # GH 44153 related # Used to be a_id != id(df["A"]), but flaky in the CI - assert not np.shares_memory(a_values, df["A"]._values) + assert a_values is not df["A"]._values df = unordered.copy() return_value = df.sort_index(ascending=False, inplace=True) From 4e8c43339df9c29a9b64bfc9afc3fe221190f4d2 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sun, 28 Nov 2021 09:54:39 -0800 Subject: [PATCH 3/3] Remove ._values --- pandas/tests/frame/methods/test_sort_index.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/methods/test_sort_index.py b/pandas/tests/frame/methods/test_sort_index.py index 6e40e95e7602f..1556a9507ab9e 100644 --- a/pandas/tests/frame/methods/test_sort_index.py +++ b/pandas/tests/frame/methods/test_sort_index.py @@ -232,7 +232,7 @@ def test_sort_index_inplace(self): tm.assert_frame_equal(df, expected) # GH 44153 related # Used to be a_id != id(df["A"]), but flaky in the CI - assert a_values is not df["A"]._values + assert a_values is not df["A"] df = unordered.copy() return_value = df.sort_index(ascending=False, inplace=True)