Skip to content
Merged
6 changes: 5 additions & 1 deletion pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,11 @@ def sanitize_array(
dtype = StringDtype(na_value=np.nan)
subarr = dtype.construct_array_type()._from_sequence(data, dtype=dtype)

if subarr is data and copy:
if (
subarr is data
or subarr.dtype == "str"
and subarr.dtype.storage == "python"
) and copy:
subarr = subarr.copy()

else:
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_constructor_copy(self, using_infer_string):
new_index = Index(arr, copy=True, name="name")
assert isinstance(new_index, Index)
assert new_index.name == "name"
if using_infer_string and HAS_PYARROW:
if using_infer_string:
tm.assert_extension_array_equal(
new_index.values, pd.array(arr, dtype="str")
)
Expand Down Expand Up @@ -357,6 +357,7 @@ def test_view_with_args_object_array_raises(self, index):
with pytest.raises(ValueError, match=msg):
index.view("i8")
elif index.dtype == "str" and not index.dtype.storage == "python":
# TODO(infer_string): Make the errors consistent
with pytest.raises(NotImplementedError, match="i8"):
index.view("i8")
else:
Expand Down