Skip to content

Commit

Permalink
TST(string dtype): Resolve xfail in test_base.py (#60713)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhshadrach authored Jan 14, 2025
1 parent fa5c255 commit 8bc8c0a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ def _str_map_nan_semantics(
else:
return self._str_map_str_or_object(dtype, na_value, arr, f, mask)

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


# error: Definition of "_concat_same_type" in base class "NDArrayBacked" is
# incompatible with definition in base class "ExtensionArray"
Expand Down
9 changes: 3 additions & 6 deletions pandas/tests/indexes/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,11 @@ def test_view_with_args_object_array_raises(self, index):
msg = "When changing to a larger dtype"
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:
msg = (
"Cannot change data-type for array of references.|"
"Cannot change data-type for object array.|"
r"Cannot change data-type for array of references\.|"
r"Cannot change data-type for object array\.|"
r"Cannot change data-type for array of strings\.|"
)
with pytest.raises(TypeError, match=msg):
index.view("i8")
Expand Down

0 comments on commit 8bc8c0a

Please sign in to comment.