-
-
Notifications
You must be signed in to change notification settings - Fork 64
Handle RuleDelayed in Map over Association expressions #1694
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,3 +193,75 @@ def test_associations_private_doctests( | |
| failure_message=assert_message, | ||
| expected_messages=expected_messages, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("str_expr", "expected_messages", "str_expected", "assert_message"), | ||
| [ | ||
| ( | ||
| "Map[F, Q[a->1, b:>Association[p->3,q->4]]]", | ||
| None, | ||
| "Q[F[a->1], F[b:>Association[p->3, q->4]]]", | ||
| "Acting on a nested association, the inner association is treated as normal.", | ||
| ), | ||
| ( | ||
| "Map[F, Q[a->1, b:>Association[p->3,q->4]],{2}]", | ||
| None, | ||
| "Q[F[a]->F[1], F[b]:>F[Association[p->3, q->4]]]", | ||
| "Acting on a nested association, the inner association is treated as normal.", | ||
| ), | ||
| ( | ||
| "Map[F, Association[a->1, b:>Association[p->3,q->4]], {0}]", | ||
| None, | ||
| "F[Association[a->1, b:>Association[p->3, q->4]]]", | ||
| "Special behavior happends at the first level.", | ||
|
||
| ), | ||
| ( | ||
| "Map[F, Association[a->1, b:>2]]", | ||
| None, | ||
| "Association[a->F[1], b:>F[2]]", | ||
| "Over associations, Map acts on the values", | ||
| ), | ||
| ( | ||
| "Map[F, Association[a->1, b:>Association[p->3,q->4]]]", | ||
| None, | ||
| "Association[a->F[1], b:>F[Association[p->3, q->4]]]", | ||
| "Acting on a nested association, the inner association is treated as normal.", | ||
| ), | ||
| ( | ||
| "Map[F, Association[a->1, b:>Association[p->3,q->4]], {1}]", | ||
| None, | ||
| "Association[a->F[1], b:>F[Association[p->3, q->4]]]", | ||
| "Special behavior happends at the first level.", | ||
|
||
| ), | ||
| # FIXME | ||
| ( | ||
| "Map[F, Association[a->1,b:>2,q]]", | ||
| None, | ||
| "Association[F[a->1], F[b:>2], F[q]]", | ||
| "Acting on an invalid association expression, works as in a normal expression.", | ||
| ), | ||
| ( | ||
| "Map[F, Association[a->1, b:>Association[p->3,q->4]], {2}]", | ||
| None, | ||
| "Association[a->1, b:>Association[F[p->3],F[q->4]]]", | ||
| "Special behavior happends at the first level.", | ||
| ), | ||
| ( | ||
| "Map[F, Association[a->1, b:>Q[p->3, q->4]], {2}]", | ||
| None, | ||
| "Association[a->1, b:>Q[F[p->3],F[q->4]]]", | ||
| "Special behavior happends at the first level.", | ||
|
||
| ), | ||
| ], | ||
| ) | ||
| @pytest.mark.xfail | ||
| def test_map_over_associations( | ||
| str_expr, expected_messages, str_expected, assert_message | ||
| ): | ||
| check_evaluation( | ||
| str_expr, | ||
| str_expected, | ||
| failure_message=assert_message, | ||
| expected_messages=expected_messages, | ||
| ) | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mistake wasn't caught in the existing tests. So, probably a test needs to be added here for the new features added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is, what should we test? For the full behavior, I have in mind a bunch of tests, that in the current implementation would not pass. The example in the comment is one of them.
To match with the WMA behavior, this method should be rewritten, and probably it would be also be interesting to define a specific class (like
ListExpression) to store validAssociationexpressions. None of this would be too complicated, but right now I do not have the time to handle it.What I could do is to list the tests here, or just add the tests to a pytest module, and mark them as xfail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you are saying that nothing in this PR right now benefits a user? There is promise, though, that one day it will?
Yes, it is better to add xfail or commented-out tests now while the issue is fresh in your mind rather than do it later. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR improves handling of some typical cases, but to cover the most general situation, we need to reimplement this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurs to me that it might be good to open an issue with this information, so we don't forget after this PR is merged. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just opened a related issue #1696, with the basic content of this discussion.