@@ -810,16 +810,14 @@ def _is_key_type_compatible(self, key):
810
810
# object kind can match anything
811
811
return key_kind == label_kind or key_kind == 'O' or label_kind == 'O' or py2_str_match
812
812
813
- def index (self , key , bool_passthrough = True ):
813
+ def index (self , key ):
814
814
"""
815
815
Translates a label key to its numerical index counterpart.
816
816
817
817
Parameters
818
818
----------
819
819
key : key
820
820
Everything usable as a key.
821
- bool_passthrough : bool, optional
822
- If set to True and key is a boolean vector, it is returned as it.
823
821
824
822
Returns
825
823
-------
@@ -890,7 +888,7 @@ def index(self, key, bool_passthrough=True):
890
888
stop = mapping [key .stop ] + 1 if key .stop is not None else None
891
889
return slice (start , stop , key .step )
892
890
# XXX: bool LArray do not pass through???
893
- elif isinstance (key , np .ndarray ) and key .dtype .kind is 'b' and bool_passthrough :
891
+ elif isinstance (key , np .ndarray ) and key .dtype .kind is 'b' :
894
892
return key
895
893
elif isinstance (key , (tuple , list , OrderedSet )):
896
894
# TODO: the result should be cached
@@ -2391,21 +2389,19 @@ def index_first_compatible(axis):
2391
2389
# -1 in to_remove are not a problem since enumerate starts at 0
2392
2390
return AxisCollection ([axis for i , axis in enumerate (self ) if i not in to_remove ])
2393
2391
2394
- def _translate_axis_key_chunk (self , axis_key , bool_passthrough = True ):
2392
+ def _translate_axis_key_chunk (self , axis_key ):
2395
2393
"""
2396
- Translates axis(es) key into axis(es) position(s).
2394
+ Translates *single axis* label-based key to an IGroup
2397
2395
2398
2396
Parameters
2399
2397
----------
2400
2398
axis_key : any kind of key
2401
- Key to select axis(es).
2402
- bool_passthrough : bool, optional
2403
- True by default.
2399
+ Key to select axis.
2404
2400
2405
2401
Returns
2406
2402
-------
2407
2403
IGroup
2408
- Positional group with valid axes (from self)
2404
+ Indices group with a valid axis (from self)
2409
2405
"""
2410
2406
axis_key = remove_nested_groups (axis_key )
2411
2407
@@ -2433,7 +2429,7 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
2433
2429
try :
2434
2430
real_axis = self [axis_key .axis ]
2435
2431
try :
2436
- axis_pos_key = real_axis .index (axis_key , bool_passthrough )
2432
+ axis_pos_key = real_axis .index (axis_key )
2437
2433
except KeyError :
2438
2434
raise ValueError ("%r is not a valid label for any axis" % axis_key )
2439
2435
return real_axis .i [axis_pos_key ]
@@ -2444,15 +2440,13 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
2444
2440
axis_key = axis_key .to_label ()
2445
2441
2446
2442
# otherwise we need to guess the axis
2447
- # TODO: instead of checking all axes, we should have a big mapping
2448
- # (in AxisCollection or LArray):
2449
- # label -> (axis, index)
2450
- # but for Pandas, this wouldn't work, we'd need label -> axis
2443
+ # TODO: instead of checking all axes, we should have a big mapping (in AxisCollection):
2444
+ # label -> (axis, index) but for sparse/multi-index, this would not work, we'd need label -> axis
2451
2445
valid_axes = []
2452
2446
# TODO: use axis_key dtype to only check compatible axes
2453
2447
for axis in self :
2454
2448
try :
2455
- axis_pos_key = axis .index (axis_key , bool_passthrough )
2449
+ axis_pos_key = axis .index (axis_key )
2456
2450
valid_axes .append (axis )
2457
2451
except KeyError :
2458
2452
continue
@@ -2466,14 +2460,22 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
2466
2460
raise ValueError ('%s is ambiguous (valid in %s)' % (axis_key , valid_axes ))
2467
2461
return valid_axes [0 ].i [axis_pos_key ]
2468
2462
2469
- def _translate_axis_key (self , axis_key , bool_passthrough = True ):
2470
- """Same as chunk.
2463
+ def _translate_axis_key (self , axis_key ):
2464
+ """
2465
+ Translates single axis label-based key to IGroup
2466
+
2467
+ Parameters
2468
+ ----------
2469
+ axis_key : any valid key
2470
+ Key to select axis.
2471
2471
2472
2472
Returns
2473
2473
-------
2474
2474
IGroup
2475
- Indices group with valid axes (from self)
2475
+ Indices group with a valid axis (from self)
2476
2476
"""
2477
+ # called from _key_to_igroups
2478
+
2477
2479
from .array import LArray
2478
2480
2479
2481
# Need to convert string keys to groups otherwise command like
@@ -2485,11 +2487,12 @@ def _translate_axis_key(self, axis_key, bool_passthrough=True):
2485
2487
axis_key = key
2486
2488
2487
2489
if isinstance (axis_key , ExprNode ):
2490
+ # FIXME: it is still possible to get here if we use a dict key in getitem !
2488
2491
raise Exception ('yada' )
2489
2492
axis_key = axis_key .evaluate (self )
2490
2493
2491
2494
# XXX: this is probably not necessary anymore
2492
- if isinstance (axis_key , LArray ) and np .issubdtype (axis_key .dtype , np .bool_ ) and bool_passthrough :
2495
+ if isinstance (axis_key , LArray ) and np .issubdtype (axis_key .dtype , np .bool_ ):
2493
2496
raise Exception ('yada' )
2494
2497
if len (axis_key .axes ) > 1 :
2495
2498
raise ValueError ("mixing ND boolean filters with other filters in getitem is not currently supported" )
@@ -2517,7 +2520,7 @@ def _translate_axis_key(self, axis_key, bool_passthrough=True):
2517
2520
# TODO: do not recheck already checked elements
2518
2521
key_chunk = axis_key .i [:size ] if isinstance (axis_key , LArray ) else axis_key [:size ]
2519
2522
try :
2520
- tkey = self ._translate_axis_key_chunk (key_chunk , bool_passthrough )
2523
+ tkey = self ._translate_axis_key_chunk (key_chunk )
2521
2524
axis = tkey .axis
2522
2525
break
2523
2526
# TODO: we should only continue when ValueError is caused by an ambiguous key, otherwise we only delay
@@ -2533,9 +2536,9 @@ def _translate_axis_key(self, axis_key, bool_passthrough=True):
2533
2536
# wrap key in LGroup
2534
2537
axis_key = axis [axis_key ]
2535
2538
# XXX: reuse tkey chunks and only translate the rest?
2536
- return self ._translate_axis_key_chunk (axis_key , bool_passthrough )
2539
+ return self ._translate_axis_key_chunk (axis_key )
2537
2540
else :
2538
- return self ._translate_axis_key_chunk (axis_key , bool_passthrough )
2541
+ return self ._translate_axis_key_chunk (axis_key )
2539
2542
2540
2543
def _key_to_igroups (self , key ):
2541
2544
"""
@@ -2593,7 +2596,6 @@ def _key_to_igroups(self, key):
2593
2596
2594
2597
# translate all keys to IGroup
2595
2598
return tuple (self ._translate_axis_key (axis_key ) for axis_key in key )
2596
-
2597
2599
else :
2598
2600
assert isinstance (key , dict )
2599
2601
0 commit comments