-
Notifications
You must be signed in to change notification settings - Fork 7
change IGroup __repr__ #447
Copy link
Copy link
Open
Labels
Description
If we want to return IGroup instead of LGroup for stuff like Axis/Group.startingwith,endingwith,... (see #438) we need to change IGroup __repr__ to somehow display the label the position corresponds to. Otherwise it makes it harder than necessary to debug any code using them. The problem is that I haven't found a way to add this without breaking the eval(repr(v)) == v which is unfortunate.
>>> a = Axis('a=a0..a5')
>>> # current situation
>>> a["a1,a3,a4"]
a['a1', 'a3', 'a4']
>>> a.i[1, 3, 4]
a.i[1, 3, 4]
>>> # alternative 1
>>> a.i[1, 3, 4]
a.i['a1' (1), 'a3' (3), 'a4' (4)]
>>> # alternative 2 -- this is more "pure" but looks less pretty
>>> a.i[1, 3, 4]
a.i[1 ('a1'), 3 ('a3'), 4 ('a4')]
>>> # alternative 3
>>> a.i[1, 3, 4]
a.i[1, 3, 4 ('a1', 'a3', 'a4')]
>>> # alternative 4
>>> a.i[1, 3, 4]
a.i[1, 3, 4] ('a1', 'a3', 'a4')
>>> # alternative 5 -- this is even more "pure" (we could make it evaluate correctly) but looks even less pretty
>>> a.i[1, 3, 4]
IGroup([1, 3, 4], axis=a, display=['a1', 'a3', 'a4'])There are potentially many other alternatives. Please suggest them if you have any idea.
Two special problems
- positional slices, for which the stop bound is not inclusive, which means that slices ending at the end of the axis are problematic (and other slices are unintuitive)
>>> a.i[1:6]
a.i[1 ('a1'): 6 (??)]
>>> # having 'a3' displayed (but not included) makes it more confusing
>>> a.i[1:3]
a.i[1 ('a1'): 3 ('a3')]
>>> # maybe doing a special case for slices would make sense (ie do not translate each bound separately but the whole "key":
>>> a.i[1:3]
a.i[1:3 ('a1':'a2')]- slices on axes with integer labels (especially if pos == label) are a bit confusing (but they are probably already confusing even though the confusion is hidden ;-)).
>>> a = Axis('a=0..10')
>>> # current
>>> a.i[1:3]
a.i[1:3]
>>> # each bound separately
>>> a.i[1:3]
a.i[1 (1): 3 (3)]
>>> # the whole key
>>> a.i[1:3]
a.i[1:3 (1:2)]My current preference goes for alternative 4 (because it will be easier to copy-paste than alternative 3) and for slices, to translate the whole key instead of each bound separately.
Reactions are currently unavailable