@@ -2157,21 +2157,43 @@ def _get_items(self):
2157
2157
return self .axes [0 ]
2158
2158
items = property (fget = _get_items )
2159
2159
2160
- def get_dtype_counts (self ):
2161
- """ return a dict of the counts of dtypes in BlockManager """
2160
+ def _get_counts (self , f ):
2161
+ """ return a dict of the counts of the function in BlockManager """
2162
2162
self ._consolidate_inplace ()
2163
2163
counts = dict ()
2164
2164
for b in self .blocks :
2165
- counts [b .dtype .name ] = counts .get (b .dtype .name , 0 ) + b .shape [0 ]
2165
+ v = f (b )
2166
+ counts [v ] = counts .get (v , 0 ) + b .shape [0 ]
2166
2167
return counts
2167
2168
2168
- def get_ftype_counts (self ):
2169
- """ return a dict of the counts of dtypes in BlockManager """
2169
+ def _get_types (self , f ):
2170
+ """ return a list of the f per item """
2170
2171
self ._consolidate_inplace ()
2171
- counts = dict ()
2172
- for b in self .blocks :
2173
- counts [b .ftype ] = counts .get (b .ftype , 0 ) + b .shape [0 ]
2174
- return counts
2172
+
2173
+ # unique
2174
+ if self .items .is_unique :
2175
+ l = [ None ] * len (self .items )
2176
+ for b in self .blocks :
2177
+ v = f (b )
2178
+ for rl in b .ref_locs :
2179
+ l [rl ] = v
2180
+ return l
2181
+
2182
+ # non-unique
2183
+ ref_locs = self ._set_ref_locs ()
2184
+ return [ f (ref_locs [i ][0 ]) for i , item in enumerate (self .items ) ]
2185
+
2186
+ def get_dtype_counts (self ):
2187
+ return self ._get_counts (lambda b : b .dtype .name )
2188
+
2189
+ def get_ftype_counts (self ):
2190
+ return self ._get_counts (lambda b : b .ftype )
2191
+
2192
+ def get_dtypes (self ):
2193
+ return self ._get_types (lambda b : b .dtype )
2194
+
2195
+ def get_ftypes (self ):
2196
+ return self ._get_types (lambda b : b .ftype )
2175
2197
2176
2198
def __getstate__ (self ):
2177
2199
block_values = [b .values for b in self .blocks ]
0 commit comments