Skip to content

Commit

Permalink
fallback with older pyarrow
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel committed Aug 22, 2024
1 parent b82dc78 commit 703b4b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 10 additions & 0 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ def _str_count(self, pat: str, flags: int = 0):
result = pc.count_substring_regex(self._pa_array, pat)
return self._convert_int_dtype(result)

def _str_find(self, sub: str, start: int = 0, end: int | None = None):
if (
pa_version_under13p0
and not (start != 0 and end is not None)
and not (start == 0 and end is None)
):
# https://github.com/pandas-dev/pandas/pull/59562/files#r1725688888
return super()._str_find(sub, start, end)
return ArrowExtensionArray._str_find(self, sub, start, end)

def _str_get_dummies(self, sep: str = "|"):
dummies_pa, labels = ArrowExtensionArray(self._pa_array)._str_get_dummies(sep)
if len(labels) == 0:
Expand Down
12 changes: 1 addition & 11 deletions pandas/tests/strings/test_find_replace.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import pytest

from pandas.compat import pa_version_under13p0
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -940,22 +939,13 @@ def test_find_bad_arg_raises(any_string_dtype):
ser.str.rfind(0)


def test_find_nan(any_string_dtype, request):
def test_find_nan(any_string_dtype):
ser = Series(
["ABCDEFG", np.nan, "DEFGHIJEF", np.nan, "XXXX"], dtype=any_string_dtype
)
expected_dtype = (
np.float64 if is_object_or_nan_string_dtype(any_string_dtype) else "Int64"
)
if (
pa_version_under13p0
and isinstance(ser.dtype, pd.StringDtype)
and ser.dtype.storage == "pyarrow"
):
# https://github.com/apache/arrow/issues/36311
mark = pytest.mark.xfail(reason="https://github.com/apache/arrow/issues/36311")
# raises pa.lib.ArrowInvalid with Negative buffer resize
request.node.add_marker(mark)

result = ser.str.find("EF")
expected = Series([4, np.nan, 1, np.nan, -1], dtype=expected_dtype)
Expand Down

0 comments on commit 703b4b7

Please sign in to comment.