Skip to content

Commit e3302bc

Browse files
[backport 2.3.x] TST (string dtype): resolve all infer_string TODO/xfails in pandas/tests/arrays (#59686) (#60020)
TST (string dtype): resolve all infer_string TODO/xfails in pandas/tests/arrays (#59686) (cherry picked from commit 4f328f0)
1 parent 99be253 commit e3302bc

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

pandas/core/arrays/string_arrow.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,13 @@ def _reduce(
408408
arr = pc.or_kleene(nas, pc.not_equal(self._pa_array, ""))
409409
else:
410410
arr = pc.not_equal(self._pa_array, "")
411-
return ArrowExtensionArray(arr)._reduce(
411+
result = ArrowExtensionArray(arr)._reduce(
412412
name, skipna=skipna, keepdims=keepdims, **kwargs
413413
)
414+
if keepdims:
415+
# ArrowExtensionArray will return a length-1 bool[pyarrow] array
416+
return result.astype(np.bool_)
417+
return result
414418

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

pandas/tests/arrays/categorical/test_analytics.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,21 @@ def test_nbytes(self):
296296
exp = 3 + 3 * 8 # 3 int8s for values + 3 int64s for categories
297297
assert cat.nbytes == exp
298298

299-
def test_memory_usage(self):
299+
def test_memory_usage(self, using_infer_string):
300300
cat = Categorical([1, 2, 3])
301301

302302
# .categories is an index, so we include the hashtable
303303
assert 0 < cat.nbytes <= cat.memory_usage()
304304
assert 0 < cat.nbytes <= cat.memory_usage(deep=True)
305305

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

309315
if not PYPY:
310316
# 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)