@@ -810,16 +810,14 @@ def _is_key_type_compatible(self, key):
810810 # object kind can match anything
811811 return key_kind == label_kind or key_kind == 'O' or label_kind == 'O' or py2_str_match
812812
813- def index (self , key , bool_passthrough = True ):
813+ def index (self , key ):
814814 """
815815 Translates a label key to its numerical index counterpart.
816816
817817 Parameters
818818 ----------
819819 key : key
820820 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.
823821
824822 Returns
825823 -------
@@ -890,7 +888,7 @@ def index(self, key, bool_passthrough=True):
890888 stop = mapping [key .stop ] + 1 if key .stop is not None else None
891889 return slice (start , stop , key .step )
892890 # 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' :
894892 return key
895893 elif isinstance (key , (tuple , list , OrderedSet )):
896894 # TODO: the result should be cached
@@ -2391,21 +2389,19 @@ def index_first_compatible(axis):
23912389 # -1 in to_remove are not a problem since enumerate starts at 0
23922390 return AxisCollection ([axis for i , axis in enumerate (self ) if i not in to_remove ])
23932391
2394- def _translate_axis_key_chunk (self , axis_key , bool_passthrough = True ):
2392+ def _translate_axis_key_chunk (self , axis_key ):
23952393 """
2396- Translates axis(es) key into axis(es) position(s).
2394+ Translates *single axis* label-based key to an IGroup
23972395
23982396 Parameters
23992397 ----------
24002398 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.
24042400
24052401 Returns
24062402 -------
24072403 IGroup
2408- Positional group with valid axes (from self)
2404+ Indices group with a valid axis (from self)
24092405 """
24102406 axis_key = remove_nested_groups (axis_key )
24112407
@@ -2433,7 +2429,7 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
24332429 try :
24342430 real_axis = self [axis_key .axis ]
24352431 try :
2436- axis_pos_key = real_axis .index (axis_key , bool_passthrough )
2432+ axis_pos_key = real_axis .index (axis_key )
24372433 except KeyError :
24382434 raise ValueError ("%r is not a valid label for any axis" % axis_key )
24392435 return real_axis .i [axis_pos_key ]
@@ -2444,15 +2440,13 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
24442440 axis_key = axis_key .to_label ()
24452441
24462442 # 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
24512445 valid_axes = []
24522446 # TODO: use axis_key dtype to only check compatible axes
24532447 for axis in self :
24542448 try :
2455- axis_pos_key = axis .index (axis_key , bool_passthrough )
2449+ axis_pos_key = axis .index (axis_key )
24562450 valid_axes .append (axis )
24572451 except KeyError :
24582452 continue
@@ -2466,14 +2460,22 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
24662460 raise ValueError ('%s is ambiguous (valid in %s)' % (axis_key , valid_axes ))
24672461 return valid_axes [0 ].i [axis_pos_key ]
24682462
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.
24712471
24722472 Returns
24732473 -------
24742474 IGroup
2475- Indices group with valid axes (from self)
2475+ Indices group with a valid axis (from self)
24762476 """
2477+ # called from _key_to_igroups
2478+
24772479 from .array import LArray
24782480
24792481 # Need to convert string keys to groups otherwise command like
@@ -2485,11 +2487,12 @@ def _translate_axis_key(self, axis_key, bool_passthrough=True):
24852487 axis_key = key
24862488
24872489 if isinstance (axis_key , ExprNode ):
2490+ # FIXME: it is still possible to get here if we use a dict key in getitem !
24882491 raise Exception ('yada' )
24892492 axis_key = axis_key .evaluate (self )
24902493
24912494 # 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_ ):
24932496 raise Exception ('yada' )
24942497 if len (axis_key .axes ) > 1 :
24952498 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):
25172520 # TODO: do not recheck already checked elements
25182521 key_chunk = axis_key .i [:size ] if isinstance (axis_key , LArray ) else axis_key [:size ]
25192522 try :
2520- tkey = self ._translate_axis_key_chunk (key_chunk , bool_passthrough )
2523+ tkey = self ._translate_axis_key_chunk (key_chunk )
25212524 axis = tkey .axis
25222525 break
25232526 # 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):
25332536 # wrap key in LGroup
25342537 axis_key = axis [axis_key ]
25352538 # 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 )
25372540 else :
2538- return self ._translate_axis_key_chunk (axis_key , bool_passthrough )
2541+ return self ._translate_axis_key_chunk (axis_key )
25392542
25402543 def _key_to_igroups (self , key ):
25412544 """
@@ -2593,7 +2596,6 @@ def _key_to_igroups(self, key):
25932596
25942597 # translate all keys to IGroup
25952598 return tuple (self ._translate_axis_key (axis_key ) for axis_key in key )
2596-
25972599 else :
25982600 assert isinstance (key , dict )
25992601
0 commit comments