Skip to content

axis[key] does not work when key contains special characters #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gdementen opened this issue Apr 4, 2017 · 4 comments
Open

axis[key] does not work when key contains special characters #200

gdementen opened this issue Apr 4, 2017 · 4 comments

Comments

@gdementen
Copy link
Contributor

gdementen commented Apr 4, 2017

Those messy string evaluations are getting in the way once more

>>> arr = ndtest(3)
>>> agg = arr.sum('a1:a2;a0:a1;a0,a2')
>>> agg
a  a1:a2  a0:a1  a0,a2
       3      1      2
>>> agg[agg.a['a1:a2']]
ValueError                                Traceback (most recent call last)
...
ValueError: a['a1':'a2'] is not a valid label for any axis
>>> agg['a1:a2']
3
>>> agg[X.a['a1:a2']]
3
@gdementen
Copy link
Contributor Author

one way to resolve this would be to implement #34, though I am reluctant to do this.

@gdementen
Copy link
Contributor Author

gdementen commented Sep 19, 2017

Another way would be to first try the key as is in Axis.__getitem__:

if key in self:
    return LGroup(key, name, self)
else:
    key = _to_key(key)
    return LGroup(key, name, self)

and AVOID using _to_key in LGroup.__init__

We could even return a PGroup directly. This would be more efficient (only translates the group once) in the usual case: use the group on an array containing that axis and slightly less efficient on the unusual case (use the group on an array without the axis).

if key in self:
    return PGroup(self.translate(key), name, self)
else:
    key = _to_key(key)
    return PGroup(self.translate(key), name, self)

@gdementen gdementen added this to the 0.26 milestone Sep 19, 2017
@gdementen
Copy link
Contributor Author

not using _to_key in LGroup.__init__ would prevent users from using LGroup directly with an "interpretable" string, which is currently the only way to make a group without axis using an interpretable string, eg:

LGroup('10..19', 'teens') 

But this kind of group should be created using another syntax anyway G['10..19'] >> 'teens' or something like that. See #23.

@gdementen gdementen self-assigned this Sep 20, 2017
@gdementen gdementen modified the milestones: 0.26, 0.27 Oct 13, 2017
@gdementen gdementen removed their assignment Nov 10, 2017
@alixdamman alixdamman modified the milestones: 0.27, 0.28 Nov 16, 2017
@alixdamman alixdamman self-assigned this Dec 1, 2017
@alixdamman alixdamman modified the milestones: 0.28, 0.29 Jan 26, 2018
@alixdamman alixdamman modified the milestones: 0.29, 0.30 Mar 1, 2018
@alixdamman alixdamman removed their assignment Aug 31, 2018
@gdementen gdementen modified the milestones: 0.30, 0.31 Jan 29, 2019
@gdementen gdementen removed this from the 0.31 milestone Aug 1, 2019
@gdementen
Copy link
Contributor Author

implementing #34 seems unavoidable.
We could also choose to avoid using/adding special characters in any label we produce (e.g. aggregate labels), but then we would either loose some information, or produce verbose labels. For example, we would get:

>>> agg = arr.sum('a1:a2;a0:a1;a0,a2')
>>> agg # option 1 (loose info)
a  a1_a2  a0_a1  a0_a2
       3      1      2
>>> agg # option 2 (verbose)
a  a1_to_a2  a0_to_a1  a0_a2
          3         1      2

PS: expanding the slices labels to its labels (e.g. a0:a2 to a0_a1_a2) does not seem like a realistic option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants