33import numpy as np
44import pytest
55
6+ from pandas .compat import PYPY
7+
68from pandas .core .dtypes .common import (
7- is_dtype_equal ,
89 is_object_dtype ,
910)
1011
@@ -77,10 +78,7 @@ def test_ndarray_compat_properties(index_or_series_obj):
7778 assert Series ([1 ]).item () == 1
7879
7980
80- # @pytest.mark.skipif(
81- # PYPY or using_string_dtype(),
82- # reason="not relevant for PyPy doesn't work properly for arrow strings",
83- # )
81+ @pytest .mark .skipif (PYPY , reason = "not relevant for PyPy" )
8482def test_memory_usage (index_or_series_memory_obj ):
8583 obj = index_or_series_memory_obj
8684 # Clear index caches so that len(obj) == 0 report 0 memory usage
@@ -96,21 +94,19 @@ def test_memory_usage(index_or_series_memory_obj):
9694
9795 def _is_object_dtype (obj ):
9896 if isinstance (obj , pd .MultiIndex ):
99- return any (is_object_dtype (level ) for level in obj .levels )
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"
100102 return is_object_dtype (obj )
101103
102- is_object = _is_object_dtype (obj ) or (is_ser and _is_object_dtype (obj .index ))
103- is_categorical = isinstance (obj .dtype , pd .CategoricalDtype ) or (
104- is_ser and isinstance (obj .index .dtype , pd .CategoricalDtype )
105- )
106- is_object_string = is_dtype_equal (obj , "string[python]" ) or (
107- is_ser and is_dtype_equal (obj .index .dtype , "string[python]" )
108- )
104+ has_objects = _is_object_dtype (obj ) or (is_ser and _is_object_dtype (obj .index ))
109105
110106 if len (obj ) == 0 :
111107 expected = 0
112108 assert res_deep == res == expected
113- elif is_object or is_categorical or is_object_string :
109+ elif has_objects :
114110 # only deep will pick them up
115111 assert res_deep > res , (res_deep , res )
116112 else :
0 commit comments