Skip to content

Commit c14104d

Browse files
committed
cleaned up functions in the "indexing chain" by removing bool_passthrough (no longer used)
1 parent 3d68c53 commit c14104d

File tree

2 files changed

+33
-33
lines changed

2 files changed

+33
-33
lines changed

larray/core/array.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,16 +1960,14 @@ def sort_key(axis):
19601960

19611961
sort_axis = renamed_to(sort_axes, 'sort_axis')
19621962

1963-
def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
1963+
def _translate_axis_key_chunk(self, axis_key):
19641964
"""
19651965
Translates axis(es) key into axis(es) position(s).
19661966
19671967
Parameters
19681968
----------
19691969
axis_key : any kind of key
19701970
Key to select axis(es).
1971-
bool_passthrough : bool, optional
1972-
True by default.
19731971
19741972
Returns
19751973
-------
@@ -2002,7 +2000,7 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
20022000
try:
20032001
real_axis = self.axes[axis_key.axis]
20042002
try:
2005-
axis_pos_key = real_axis.index(axis_key, bool_passthrough)
2003+
axis_pos_key = real_axis.index(axis_key)
20062004
except KeyError:
20072005
raise ValueError("%r is not a valid label for any axis" % axis_key)
20082006
return real_axis.i[axis_pos_key]
@@ -2021,7 +2019,7 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
20212019
# TODO: use axis_key dtype to only check compatible axes
20222020
for axis in self.axes:
20232021
try:
2024-
axis_pos_key = axis.index(axis_key, bool_passthrough)
2022+
axis_pos_key = axis.index(axis_key)
20252023
valid_axes.append(axis)
20262024
except KeyError:
20272025
continue
@@ -2035,7 +2033,7 @@ def _translate_axis_key_chunk(self, axis_key, bool_passthrough=True):
20352033
raise ValueError('%s is ambiguous (valid in %s)' % (axis_key, valid_axes))
20362034
return valid_axes[0].i[axis_pos_key]
20372035

2038-
def _translate_axis_key(self, axis_key, bool_passthrough=True):
2036+
def _translate_axis_key(self, axis_key):
20392037
"""Same as chunk.
20402038
20412039
Returns
@@ -2067,7 +2065,7 @@ def _translate_axis_key(self, axis_key, bool_passthrough=True):
20672065
# TODO: do not recheck already checked elements
20682066
key_chunk = axis_key.i[:size] if isinstance(axis_key, LArray) else axis_key[:size]
20692067
try:
2070-
tkey = self._translate_axis_key_chunk(key_chunk, bool_passthrough)
2068+
tkey = self._translate_axis_key_chunk(key_chunk)
20712069
axis = tkey.axis
20722070
break
20732071
except ValueError:
@@ -2081,9 +2079,9 @@ def _translate_axis_key(self, axis_key, bool_passthrough=True):
20812079
# wrap key in LGroup
20822080
axis_key = axis[axis_key]
20832081
# XXX: reuse tkey chunks and only translate the rest?
2084-
return self._translate_axis_key_chunk(axis_key, bool_passthrough)
2082+
return self._translate_axis_key_chunk(axis_key)
20852083
else:
2086-
return self._translate_axis_key_chunk(axis_key, bool_passthrough)
2084+
return self._translate_axis_key_chunk(axis_key)
20872085

20882086
def _guess_axis(self, axis_key):
20892087
if isinstance(axis_key, Group):

larray/core/axis.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)