Skip to content

Commit 8bc8c0a

Browse files
authored
TST(string dtype): Resolve xfail in test_base.py (#60713)
1 parent fa5c255 commit 8bc8c0a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pandas/core/arrays/string_.py

+5
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ def _str_map_nan_semantics(
533533
else:
534534
return self._str_map_str_or_object(dtype, na_value, arr, f, mask)
535535

536+
def view(self, dtype: Dtype | None = None) -> ArrayLike:
537+
if dtype is not None:
538+
raise TypeError("Cannot change data-type for string array.")
539+
return super().view(dtype=dtype)
540+
536541

537542
# error: Definition of "_concat_same_type" in base class "NDArrayBacked" is
538543
# incompatible with definition in base class "ExtensionArray"

pandas/tests/indexes/test_base.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,11 @@ def test_view_with_args_object_array_raises(self, index):
351351
msg = "When changing to a larger dtype"
352352
with pytest.raises(ValueError, match=msg):
353353
index.view("i8")
354-
elif index.dtype == "str" and not index.dtype.storage == "python":
355-
# TODO(infer_string): Make the errors consistent
356-
with pytest.raises(NotImplementedError, match="i8"):
357-
index.view("i8")
358354
else:
359355
msg = (
360-
"Cannot change data-type for array of references.|"
361-
"Cannot change data-type for object array.|"
356+
r"Cannot change data-type for array of references\.|"
357+
r"Cannot change data-type for object array\.|"
358+
r"Cannot change data-type for array of strings\.|"
362359
)
363360
with pytest.raises(TypeError, match=msg):
364361
index.view("i8")

0 commit comments

Comments
 (0)