Skip to content
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

allow ; in get/setitem #983

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gdementen
Copy link
Contributor

No description provided.

so that we can target multiple axes in a single string. eg. arr['a1;b1'] or arr['b1..b3;a2,a1']
@gdementen gdementen requested a review from alixdamman October 11, 2021 08:47
Copy link
Collaborator

@alixdamman alixdamman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I wonder if the tutorial section about selections shouldn't be updated ?
  2. I wonder if all the logic about keys should not be moved from the group.py module to a separate new module (since, as I understand it, the functions present in group.py are also used in axis.py and array.py)?

@@ -2811,6 +2811,12 @@ def _key_to_axis_indices_dict(self, key):
"""
from .array import Array

if isinstance(key, str) and ';' in key:
# FIXME: it would be more logical to use _to_keys(key) instead but this breaks
# the "target an aggregate with its key" feature (test_getitem_on_group_agg).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry but I don't understand what you mean by "target an aggregate with its key" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that the two last lines both work:

>>> arr = ndtest(4)
>>> arr
a  a0  a1  a2  a3
    0   1   2   3
>>> a = arr.a
>>> g1 = a['a1,a3'] >> 'g1'
>>> g2 = a['a0,a2']
>>> agg = arr.sum((g1, g2))
>>> agg
a  g1  a0,a2
    4      2
>>> agg[g1]
4
>>> agg[g2]
2

This is an obscure feature of LArray which I thought users would want to use but was a pain to implement and "keep working over the years". It makes the code ugly in a few places and costs a bit of performance too... and AFAIK nobody uses it so we should scrap it I think.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. In that case, add an issue for that (or we will rapidly completely forget about it). Thx.

@@ -651,6 +651,14 @@ def test_getitem_guess_axis(array):
res = arr['b[l1]']
assert_array_equal(res, arr.data[:, 0])

# several axes in same string (guess axis)
res = arr['l0;l2']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update the tutorial with a similar example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

assert res == 1

# several axes in same string (with axis information)
res = arr['a[l1];b[l2]']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@gdementen
Copy link
Contributor Author

1. I **wonder** if the tutorial section about selections shouldn't be updated ?

Yes indeed. Thanks for keeping my lazyness in check 😄.

2. I **wonder** if all the logic about keys should not be moved from the `group.py` module to a separate new module (since, as I understand it, the functions present in `group.py` are also used in `axis.py` and `array.py`)?

That would make sense but I don't know if that's easily feasible (cyclic imports etc.). Needs to check.

@alixdamman
Copy link
Collaborator

That would make sense but I don't know if that's easily feasible (cyclic imports etc.). Needs to check.

Maybe adding an ABCGroup in abstractbases.py would be enough.

@gdementen gdementen added this to the 0.34 milestone Sep 16, 2022
@gdementen gdementen self-assigned this Sep 20, 2022
@gdementen gdementen modified the milestones: 0.34, 0.35 Oct 21, 2022
@gdementen gdementen modified the milestones: 0.35, 0.36 Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants