1
1
""" common utilities """
2
-
3
2
import itertools
4
3
from warnings import catch_warnings , filterwarnings
5
4
@@ -29,7 +28,7 @@ def _axify(obj, key, axis):
29
28
class Base :
30
29
""" indexing comprehensive base class """
31
30
32
- _objs = {"series" , "frame" }
31
+ _kinds = {"series" , "frame" }
33
32
_typs = {
34
33
"ints" ,
35
34
"uints" ,
@@ -101,13 +100,12 @@ def setup_method(self, method):
101
100
self .series_empty = Series ()
102
101
103
102
# form agglomerates
104
- for o in self ._objs :
105
-
103
+ for kind in self ._kinds :
106
104
d = dict ()
107
- for t in self ._typs :
108
- d [t ] = getattr (self , "{o }_{t }" .format (o = o , t = t ), None )
105
+ for typ in self ._typs :
106
+ d [typ ] = getattr (self , "{kind }_{typ }" .format (kind = kind , typ = typ ) )
109
107
110
- setattr (self , o , d )
108
+ setattr (self , kind , d )
111
109
112
110
def generate_indices (self , f , values = False ):
113
111
""" generate the indices
@@ -117,7 +115,7 @@ def generate_indices(self, f, values=False):
117
115
118
116
axes = f .axes
119
117
if values :
120
- axes = (list (range (len (a ))) for a in axes )
118
+ axes = (list (range (len (ax ))) for ax in axes )
121
119
122
120
return itertools .product (* axes )
123
121
@@ -186,34 +184,34 @@ def check_result(
186
184
method2 ,
187
185
key2 ,
188
186
typs = None ,
189
- objs = None ,
187
+ kinds = None ,
190
188
axes = None ,
191
189
fails = None ,
192
190
):
193
- def _eq (t , o , a , obj , k1 , k2 ):
191
+ def _eq (typ , kind , axis , obj , key1 , key2 ):
194
192
""" compare equal for these 2 keys """
195
-
196
- if a is not None and a > obj .ndim - 1 :
193
+ if axis > obj .ndim - 1 :
197
194
return
198
195
199
196
def _print (result , error = None ):
200
- if error is not None :
201
- error = str (error )
202
- v = (
197
+ err = str (error ) if error is not None else ""
198
+ msg = (
203
199
"%-16.16s [%-16.16s]: [typ->%-8.8s,obj->%-8.8s,"
204
200
"key1->(%-4.4s),key2->(%-4.4s),axis->%s] %s"
205
- % (name , result , t , o , method1 , method2 , a , error or "" )
201
+ % (name , result , typ , kind , method1 , method2 , axis , err )
206
202
)
207
203
if _verbose :
208
- pprint_thing (v )
204
+ pprint_thing (msg )
209
205
210
206
try :
211
- rs = getattr (obj , method1 ).__getitem__ (_axify (obj , k1 , a ))
207
+ rs = getattr (obj , method1 ).__getitem__ (_axify (obj , key1 , axis ))
212
208
213
209
with catch_warnings (record = True ):
214
210
filterwarnings ("ignore" , "\\ n.ix" , FutureWarning )
215
211
try :
216
- xp = self .get_result (obj , method2 , k2 , a )
212
+ xp = self .get_result (
213
+ obj = obj , method = method2 , key = key2 , axis = axis
214
+ )
217
215
except (KeyError , IndexError ):
218
216
# TODO: why is this allowed?
219
217
result = "no comp"
@@ -228,8 +226,8 @@ def _print(result, error=None):
228
226
else :
229
227
tm .assert_equal (rs , xp )
230
228
result = "ok"
231
- except AssertionError as e :
232
- detail = str (e )
229
+ except AssertionError as exc :
230
+ detail = str (exc )
233
231
result = "fail"
234
232
235
233
# reverse the checks
@@ -258,36 +256,25 @@ def _print(result, error=None):
258
256
if typs is None :
259
257
typs = self ._typs
260
258
261
- if objs is None :
262
- objs = self ._objs
259
+ if kinds is None :
260
+ kinds = self ._kinds
263
261
264
- if axes is not None :
265
- if not isinstance (axes , (tuple , list )):
266
- axes = [axes ]
267
- else :
268
- axes = list (axes )
269
- else :
262
+ if axes is None :
270
263
axes = [0 , 1 ]
264
+ elif not isinstance (axes , (tuple , list )):
265
+ assert isinstance (axes , int )
266
+ axes = [axes ]
271
267
272
268
# check
273
- for o in objs :
274
- if o not in self ._objs :
269
+ for kind in kinds :
270
+ if kind not in self ._kinds :
275
271
continue
276
272
277
- d = getattr (self , o )
278
- for a in axes :
279
- for t in typs :
280
- if t not in self ._typs :
273
+ d = getattr (self , kind )
274
+ for ax in axes :
275
+ for typ in typs :
276
+ if typ not in self ._typs :
281
277
continue
282
278
283
- obj = d [t ]
284
- if obj is None :
285
- continue
286
-
287
- def _call (obj = obj ):
288
- obj = obj .copy ()
289
-
290
- k2 = key2
291
- _eq (t , o , a , obj , key1 , k2 )
292
-
293
- _call ()
279
+ obj = d [typ ]
280
+ _eq (typ = typ , kind = kind , axis = ax , obj = obj , key1 = key1 , key2 = key2 )
0 commit comments