From 84d7c1f97c63c7bccdb8ebe83e682d70576c7d18 Mon Sep 17 00:00:00 2001 From: Matteo Paltenghi Date: Mon, 27 Jan 2025 14:25:17 +0100 Subject: [PATCH 1/3] add test for when str array raises type error --- pandas/tests/indexes/test_base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 608158d40cf23..562f1049ba856 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1351,6 +1351,10 @@ def test_index_round(self, decimals, expected_results): tm.assert_index_equal(result, expected) + def test_string_array_view_type_error(self): + arr = pd.array(["a", "b", "c"], dtype="string") + with pytest.raises(TypeError, match="Cannot change data-type for string array."): + arr.view("i8") class TestMixedIntIndex: # Mostly the tests from common.py for which the results differ From 7b312ae40d54dd41c0b0a9fe54bad411e6f28751 Mon Sep 17 00:00:00 2001 From: Matteo Paltenghi Date: Mon, 27 Jan 2025 14:29:44 +0100 Subject: [PATCH 2/3] fix formatting: ruff-format --- pandas/tests/indexes/test_base.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 562f1049ba856..a9087a3a4d776 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1353,9 +1353,12 @@ def test_index_round(self, decimals, expected_results): def test_string_array_view_type_error(self): arr = pd.array(["a", "b", "c"], dtype="string") - with pytest.raises(TypeError, match="Cannot change data-type for string array."): + with pytest.raises( + TypeError, match="Cannot change data-type for string array." + ): arr.view("i8") + class TestMixedIntIndex: # Mostly the tests from common.py for which the results differ # in py2 and py3 because ints and strings are uncomparable in py3 From 660803c8663188b5b5678df5b4ea33d87c31c150 Mon Sep 17 00:00:00 2001 From: Matteo Paltenghi Date: Mon, 27 Jan 2025 23:21:12 +0100 Subject: [PATCH 3/3] moved test to tests/arrays/string_/test_string.py file --- pandas/tests/arrays/string_/test_string.py | 6 ++++++ pandas/tests/indexes/test_base.py | 7 ------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pandas/tests/arrays/string_/test_string.py b/pandas/tests/arrays/string_/test_string.py index f875873863b4d..336a0fef69170 100644 --- a/pandas/tests/arrays/string_/test_string.py +++ b/pandas/tests/arrays/string_/test_string.py @@ -758,3 +758,9 @@ def test_tolist(dtype): result = arr.tolist() expected = vals tm.assert_equal(result, expected) + + +def test_string_array_view_type_error(): + arr = pd.array(["a", "b", "c"], dtype="string") + with pytest.raises(TypeError, match="Cannot change data-type for string array."): + arr.view("i8") diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index a9087a3a4d776..608158d40cf23 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -1351,13 +1351,6 @@ def test_index_round(self, decimals, expected_results): tm.assert_index_equal(result, expected) - def test_string_array_view_type_error(self): - arr = pd.array(["a", "b", "c"], dtype="string") - with pytest.raises( - TypeError, match="Cannot change data-type for string array." - ): - arr.view("i8") - class TestMixedIntIndex: # Mostly the tests from common.py for which the results differ