Repository navigation
change IGroup __repr__ #447
Description
Activity
Here is a concrete example when you would get an IGroup without explicitly asking for it:
>>> people = Axis(['Bruce Wayne', 'Bruce Willis', 'Arthur Dent'], 'people') >>> group = people.startingwith('Bru') >>> # current >>> group people['Bruce Wayne', 'Bruce Willis'] >>> # alternative 4 >>> group people.i[0, 1] ('Bruce Wayne', 'Bruce Willis') >>> # current >>> group.containing('Will') people['Bruce Willis'] >>> # alternative 4 >>> group.containing('Will') people.i[1] ('Bruce Willis')
Yet another option is to blur the difference between IGroup and LGroup and only display the position in the presence of duplicate labels:
>>> people = Axis(['Bruce', 'Bruce', 'Bru'], 'people') >>> group = people.startingwith('Bru') >>> # current (which is broken and select the first or last 'Bruce' twice) >>> group people['Bruce', 'Bruce', 'Bru'] >>> # alternative 4 >>> group people.i[0, 1, 2] ('Bruce', 'Bruce', 'Bru') >>> # alternative 6. It is the nicest of all IMO but breaks eval(repr) badly >>> # when there is no duplicate, it is indistinguishable from an LGroup (which is both >>> # a bad and a good thing) >>> group people['Bruce' (0), 'Bruce' (1), 'Bru'] >>> people.i[1, 2] people['Bruce' (1), 'Bru']
My first choice is also
alternative 4(which, indeed, allows easy copy/paste) and to translate the whole key instead of each bound separately for slices.I wouldn't "blur" the difference between PGroup and LGroup. It's good to know when you are dealing with PGroup or LGroup. Explicit is better than implicit.
I wonder if it wouldn't be simpler to just ensure we have no duplicate label on Axis construction (it would incur a performance penalty but I assume it would be very small -- or even negligible in our models I think) by deduplicating them:
Something like:
>>> Axis('test=a,a,a,a') Axis(['a#0', 'a#1', 'a#2', 'a#3'], 'a')
or maybe start counting at 1??? Unsure what would be least confusing. See what Pandas does for columns.
Then we can always use IGroups (except for X.) but display them like LGroups
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.There are potentially many other alternatives. Please suggest them if you have any idea.
Two special problems
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.