Skip to content

Commit 04ae6ad

Browse files
TST (string dtype): resolve all infer_string TODO/xfails in pandas/tests/arrays
1 parent e07453e commit 04ae6ad

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

pandas/core/arrays/string_arrow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,13 @@ def _reduce(
488488
arr = pc.or_kleene(nas, pc.not_equal(self._pa_array, ""))
489489
else:
490490
arr = pc.not_equal(self._pa_array, "")
491-
return ArrowExtensionArray(arr)._reduce(
491+
result = ArrowExtensionArray(arr)._reduce(
492492
name, skipna=skipna, keepdims=keepdims, **kwargs
493493
)
494+
if keepdims:
495+
# ArrowExtensionArray will return a length-1 bool[pyarrow] array
496+
return result.astype(np.bool_)
497+
return result
494498

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

pandas/tests/arrays/categorical/test_analytics.py

Lines changed: 9 additions & 11 deletions
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

Lines changed: 1 addition & 6 deletions
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)