Skip to content

allow passing a function to set_labels (which will pass labels through the function) #536

@gdementen

Description

@gdementen

The end goal is to make transforming axis labels easier. eg lowercase -> uppercase or the opposite

This is technically easy, but the difficulty is to find a nice syntax. Currently we have to write:

>>> arr = ndtest(3)
>>> arr.set_labels('a', [l.upper() for l in arr.a.labels])
a  A0  A1  A2
    0   1   2
>>> # or
>>> arr.set_labels('a', map(str.upper, arr.a.labels))
a  A0  A1  A2
    0   1   2

maybe this would do:

>>> arr.map_labels('a', str.upper)
a  A0  A1  A2
    0   1   2
>>> # or this
>>> arr.set_axes('a', a.str.upper())
a  A0  A1  A2
    0   1   2

Where the str namespace would contain most str operations vectorized :
capitalize, casefold, center, count, encode, endswith, expandtabs, find, format, format_map, index, isalnum, isalpha, isdecimal, isdigit, isidentifier, islower, isnumeric, isprintable, isspace, istitle, isupper, join, ljust, lower, lstrip, maketrans, partition, replace, rfind, rindex, rjust, rpartition, rsplit, rstrip, split, splitlines, startswith, strip, swapcase, title, translate, upper, zfill

I think we will need the later at some point anyway, so the question is whether it is worth having the first one too to avoid having to repeat the axis name.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions