Skip to content

Commit 430264d

Browse files
committed
fixed the case where VG(key) is not in Axis but key is in Axis
The problem is that "VG(key) in axis" returns True
1 parent d3401a9 commit 430264d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

larray/core.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,12 +1292,22 @@ def __array__(self, dtype=None):
12921292
def _translate_axis_key(self, axis, key):
12931293
# we do not use axis.translate because we have to let Pandas do the
12941294
# label -> position conversion
1295-
if key in axis:
1296-
return key
1297-
12981295
if isinstance(key, ValueGroup):
1296+
# this case is tricky because axis.__contains__(VG) use VG.key
1297+
# (because of the way VG.__hash__ is implemented), which means
1298+
# VG.key in axis => VG in axis even though only VG.key is really
1299+
# in the actual Axis ticks (and Pandas Index) and NOT the VG itself
1300+
if key in axis:
1301+
# we check if the VG itself is *really* in the axis
1302+
idx = axis.translate(key)
1303+
if isinstance(axis.labels[idx], ValueGroup):
1304+
return key
1305+
12991306
key = key.key
13001307

1308+
if key in axis:
1309+
return key
1310+
13011311
return to_key(key)
13021312

13031313
#XXX: we only need axes length, so we might want to move this out of the

0 commit comments

Comments
 (0)