Skip to content

Commit 2b5aa95

Browse files
TST (string dtype): resolve skip in misc test_memory_usage
1 parent 7817cb2 commit 2b5aa95

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

pandas/tests/base/test_misc.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
import numpy as np
44
import pytest
55

6-
from pandas._config import using_string_dtype
7-
86
from pandas.compat import PYPY
97

108
from pandas.core.dtypes.common import (
11-
is_dtype_equal,
129
is_object_dtype,
1310
)
1411

@@ -81,10 +78,7 @@ def test_ndarray_compat_properties(index_or_series_obj):
8178
assert Series([1]).item() == 1
8279

8380

84-
@pytest.mark.skipif(
85-
PYPY or using_string_dtype(),
86-
reason="not relevant for PyPy doesn't work properly for arrow strings",
87-
)
81+
@pytest.mark.skipif(PYPY, reason="not relevant for PyPy")
8882
def test_memory_usage(index_or_series_memory_obj):
8983
obj = index_or_series_memory_obj
9084
# Clear index caches so that len(obj) == 0 report 0 memory usage
@@ -98,18 +92,21 @@ def test_memory_usage(index_or_series_memory_obj):
9892
res = obj.memory_usage()
9993
res_deep = obj.memory_usage(deep=True)
10094

101-
is_object = is_object_dtype(obj) or (is_ser and is_object_dtype(obj.index))
102-
is_categorical = isinstance(obj.dtype, pd.CategoricalDtype) or (
103-
is_ser and isinstance(obj.index.dtype, pd.CategoricalDtype)
104-
)
105-
is_object_string = is_dtype_equal(obj, "string[python]") or (
106-
is_ser and is_dtype_equal(obj.index.dtype, "string[python]")
107-
)
95+
def _is_object_dtype(obj):
96+
if isinstance(obj, pd.MultiIndex):
97+
return any(is_object_dtype(level) for level in obj.levels)
98+
elif isinstance(obj.dtype, pd.CategoricalDtype):
99+
return is_object_dtype(obj.dtype.categories)
100+
elif isinstance(obj.dtype, pd.StringDtype):
101+
return obj.dtype.storage == "python"
102+
return is_object_dtype(obj)
103+
104+
has_objects = _is_object_dtype(obj) or (is_ser and _is_object_dtype(obj.index))
108105

109106
if len(obj) == 0:
110107
expected = 0
111108
assert res_deep == res == expected
112-
elif is_object or is_categorical or is_object_string:
109+
elif has_objects:
113110
# only deep will pick them up
114111
assert res_deep > res
115112
else:

0 commit comments

Comments
 (0)