Skip to content

Implement Arrow String Array that is compatible with NumPy semantics #54533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use bool instead of object
  • Loading branch information
phofl committed Aug 21, 2023
commit 1e732c9760f1f62b1edf22ecf6aa31493e6a48b2
2 changes: 1 addition & 1 deletion pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def _str_find(self, sub: str, start: int = 0, end: int | None = None):

def _cmp_method(self, other, op):
result = super()._cmp_method(other, op)
return result.to_numpy(na_value=False)
return result.to_numpy(na_value=False).astype(np.bool_)

def value_counts(self, dropna: bool = True):
from pandas import Series
Expand Down
14 changes: 9 additions & 5 deletions pandas/tests/arrays/string_/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ def test_comparison_methods_scalar(comparison_op, dtype):
result = getattr(a, op_name)(other)
if dtype.storage == "pyarrow_numpy":
expected = np.array([getattr(item, op_name)(other) for item in a], dtype=object)
expected = pd.array(expected, dtype="boolean").to_numpy(na_value=False)
expected = (
pd.array(expected, dtype="boolean")
.to_numpy(na_value=False)
.astype(np.bool_)
)
tm.assert_numpy_array_equal(result, expected)
else:
expected_dtype = "boolean[pyarrow]" if dtype.storage == "pyarrow" else "boolean"
Expand All @@ -221,7 +225,7 @@ def test_comparison_methods_scalar_pd_na(comparison_op, dtype):
result = getattr(a, op_name)(pd.NA)

if dtype.storage == "pyarrow_numpy":
expected = np.array([False, False, False], dtype=object)
expected = np.array([False, False, False])
tm.assert_numpy_array_equal(result, expected)
else:
expected_dtype = "boolean[pyarrow]" if dtype.storage == "pyarrow" else "boolean"
Expand Down Expand Up @@ -249,7 +253,7 @@ def test_comparison_methods_scalar_not_string(comparison_op, dtype):
"__eq__": [False, False, False],
"__ne__": [True, False, True],
}[op_name]
expected = np.array(expected_data, dtype=object)
expected = np.array(expected_data)
tm.assert_numpy_array_equal(result, expected)
else:
expected_data = {"__eq__": [False, None, False], "__ne__": [True, None, True]}[
Expand All @@ -267,12 +271,12 @@ def test_comparison_methods_array(comparison_op, dtype):
other = [None, None, "c"]
result = getattr(a, op_name)(other)
if dtype.storage == "pyarrow_numpy":
expected = np.array([False, False, False], dtype=object)
expected = np.array([False, False, False])
expected[-1] = getattr(other[-1], op_name)(a[-1])
tm.assert_numpy_array_equal(result, expected)

result = getattr(a, op_name)(pd.NA)
expected = np.array([False, False, False], dtype=object)
expected = np.array([False, False, False])
tm.assert_numpy_array_equal(result, expected)

else:
Expand Down