Skip to content

Commit 4f328f0

Browse files
TST (string dtype): resolve all infer_string TODO/xfails in pandas/tests/arrays (pandas-dev#59686)
1 parent 88554d0 commit 4f328f0

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

pandas/core/arrays/string_arrow.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,13 @@ def _reduce(
427427
arr = pc.or_kleene(nas, pc.not_equal(self._pa_array, ""))
428428
else:
429429
arr = pc.not_equal(self._pa_array, "")
430-
return ArrowExtensionArray(arr)._reduce(
430+
result = ArrowExtensionArray(arr)._reduce(
431431
name, skipna=skipna, keepdims=keepdims, **kwargs
432432
)
433+
if keepdims:
434+
# ArrowExtensionArray will return a length-1 bool[pyarrow] array
435+
return result.astype(np.bool_)
436+
return result
433437

434438
result = self._reduce_calc(name, skipna=skipna, keepdims=keepdims, **kwargs)
435439
if name in ("argmin", "argmax") and isinstance(result, pa.Array):

pandas/tests/arrays/categorical/test_analytics.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44
import numpy as np
55
import pytest
66

7-
from pandas._config import using_string_dtype
8-
9-
from pandas.compat import (
10-
HAS_PYARROW,
11-
PYPY,
12-
)
7+
from pandas.compat import PYPY
138

149
from pandas import (
1510
Categorical,
@@ -299,18 +294,21 @@ def test_nbytes(self):
299294
exp = 3 + 3 * 8 # 3 int8s for values + 3 int64s for categories
300295
assert cat.nbytes == exp
301296

302-
@pytest.mark.xfail(
303-
using_string_dtype() and HAS_PYARROW, reason="TODO(infer_string)"
304-
)
305-
def test_memory_usage(self):
297+
def test_memory_usage(self, using_infer_string):
306298
cat = Categorical([1, 2, 3])
307299

308300
# .categories is an index, so we include the hashtable
309301
assert 0 < cat.nbytes <= cat.memory_usage()
310302
assert 0 < cat.nbytes <= cat.memory_usage(deep=True)
311303

312304
cat = Categorical(["foo", "foo", "bar"])
313-
assert cat.memory_usage(deep=True) > cat.nbytes
305+
if using_infer_string:
306+
if cat.categories.dtype.storage == "python":
307+
assert cat.memory_usage(deep=True) > cat.nbytes
308+
else:
309+
assert cat.memory_usage(deep=True) >= cat.nbytes
310+
else:
311+
assert cat.memory_usage(deep=True) > cat.nbytes
314312

315313
if not PYPY:
316314
# sys.getsizeof will call the .memory_usage with

pandas/tests/arrays/integer/test_reduction.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import numpy as np
22
import pytest
33

4-
from pandas.compat import HAS_PYARROW
5-
64
import pandas as pd
75
from pandas import (
86
DataFrame,
@@ -104,10 +102,7 @@ def test_groupby_reductions(op, expected):
104102
["all", Series([True, True, True], index=["A", "B", "C"], dtype="boolean")],
105103
],
106104
)
107-
def test_mixed_reductions(request, op, expected, using_infer_string):
108-
if op in ["any", "all"] and using_infer_string and HAS_PYARROW:
109-
# TODO(infer_string) inconsistent result type
110-
request.applymarker(pytest.mark.xfail(reason="TODO(infer_string)"))
105+
def test_mixed_reductions(op, expected):
111106
df = DataFrame(
112107
{
113108
"A": ["a", "b", "b"],

0 commit comments

Comments
 (0)