3
3
import numpy as np
4
4
import pytest
5
5
6
- from pandas ._config import using_string_dtype
7
-
8
6
from pandas .compat import PYPY
9
7
10
8
from pandas .core .dtypes .common import (
11
- is_dtype_equal ,
12
9
is_object_dtype ,
13
10
)
14
11
@@ -81,10 +78,7 @@ def test_ndarray_compat_properties(index_or_series_obj):
81
78
assert Series ([1 ]).item () == 1
82
79
83
80
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" )
88
82
def test_memory_usage (index_or_series_memory_obj ):
89
83
obj = index_or_series_memory_obj
90
84
# 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):
98
92
res = obj .memory_usage ()
99
93
res_deep = obj .memory_usage (deep = True )
100
94
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 ))
108
105
109
106
if len (obj ) == 0 :
110
107
expected = 0
111
108
assert res_deep == res == expected
112
- elif is_object or is_categorical or is_object_string :
109
+ elif has_objects :
113
110
# only deep will pick them up
114
111
assert res_deep > res
115
112
else :
0 commit comments