-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Description
Unsure what the best API for this would be. It would be pretty easy to add this as Axis methods (e.g. before and after).
For vs who needed this functionality (but she is not the first user who needed something like this), I used the following code:
def label_before(axis, label, n=1):
target_label_idx = axis.index(label) - n
if target_label_idx < 0:
plural_suffix = "s" if n > 1 else ""
raise ValueError(f"{n} position{plural_suffix} before {label!r} is before the start of the '{axis}' axis")
return axis.i[target_label_idx]
def label_after(axis, label, n=1):
target_label_idx = axis.index(label) + n
if target_label_idx >= len(axis):
plural_suffix = "s" if n > 1 else ""
raise ValueError(f"{n} position{plural_suffix} after {label!r} is after the end of the '{axis}' axis")
return axis.i[target_label_idx]
Moving those to axis methods would be trivial. But I am now wondering:
- couldn't this be achieved using shift? Isn't this the symptom that shift is hard to use?
- is there a way to express this using the string syntax?
- how will those new methods behave when using X. syntax?
The last two could come later though.