Skip to content

Commit 4acd264

Browse files
committed
Backport PR #60713: TST(string dtype): Resolve xfail in test_base.py
1 parent 3079aa0 commit 4acd264

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
@@ -531,6 +531,11 @@ def _str_map_nan_semantics(
531531
else:
532532
return self._str_map_str_or_object(dtype, na_value, arr, f, mask)
533533

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

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

pandas/tests/indexes/test_base.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -354,14 +354,11 @@ def test_view_with_args_object_array_raises(self, index):
354354
msg = "When changing to a larger dtype"
355355
with pytest.raises(ValueError, match=msg):
356356
index.view("i8")
357-
elif index.dtype == "str" and not index.dtype.storage == "python":
358-
# TODO(infer_string): Make the errors consistent
359-
with pytest.raises(NotImplementedError, match="i8"):
360-
index.view("i8")
361357
else:
362358
msg = (
363-
"Cannot change data-type for array of references|"
364-
"Cannot change data-type for object array|"
359+
r"Cannot change data-type for array of references\.|"
360+
r"Cannot change data-type for object array\.|"
361+
r"Cannot change data-type for array of strings\.|"
365362
)
366363
with pytest.raises(TypeError, match=msg):
367364
index.view("i8")

0 commit comments

Comments
 (0)