Skip to content

Conversation

@mmatera
Copy link
Contributor

@mmatera mmatera commented Feb 12, 2026

One slight change over #1692. Also, I add a comment about differences with WMA output in the case that the Association expression does not have the form Association[__(Rule|RuleDelayed)].

@rocky
Copy link
Member

rocky commented Feb 12, 2026

LGTM. Thanks for the generalization and clarification.

@Li-Xiang-Ideal
Copy link
Contributor

btw now MapAt maps on values for Association[__Rule] only:

if hasattr(replace_element, "head") and replace_element.head is SymbolRule:
new_elements[j] = Expression(
SymbolRule,
replace_element.elements[0],
Expression(f, replace_element.elements[1]),
)

#

if is_association and level.has_form(("Rule", "RuleDeyaled"), 2):
if is_association and level.has_form(("Rule", "RuleDelayed"), 2):
Copy link
Member

@rocky rocky Feb 12, 2026

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.

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 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 valid Association expressions. 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.

Copy link
Member

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?

So you are saying that nothing in this PR right now benefits a user? There is promise, though, that one day it will?

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 valid Association expressions. 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.

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.

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 question is, what should we test?

So you are saying that nothing in this PR right now benefits a user? There is promise, though, that one day it will?

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 valid Association expressions. 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.

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.

This PR improves handling of some typical cases, but to cover the most general situation, we need to reimplement this.

"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.",
Copy link
Member

Choose a reason for hiding this comment

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

happends -> occurs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

"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.",
Copy link
Member

Choose a reason for hiding this comment

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

happends -> occurs

"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.",
Copy link
Member

Choose a reason for hiding this comment

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

happends -> occurs

@mmatera
Copy link
Contributor Author

mmatera commented Feb 12, 2026

btw now MapAt maps on values for Association[__Rule] only:

if hasattr(replace_element, "head") and replace_element.head is SymbolRule:
new_elements[j] = Expression(
SymbolRule,
replace_element.elements[0],
Expression(f, replace_element.elements[1]),
)

thanks for the observation!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants