Problem Using Evaluated Replace with Associations

If I define some function like:

toISOdate[data_List]:=DateString[data,{"Year","-","Month","-","Day"}]


and try to applicate it in an Association

ass = <|"date" -> {{2014, 1, 1}, {2014, 1, 2}}|>


as:

Replace[ass, a:{_, _, _} :> toISOdate[a], ∞]


I get, the non calculated form:

<|"date" -> {toISOdate[{2014, 1, 1}], toISOdate[{2014, 1, 2}]}|>


<|"date" -> {"2014-01-01", "2014-01-02"}|>


If I use Normal into ass as:

Replace[Normal@ass, (a : {_, _, _}) :> toISOdate[a], ∞]


I get the correct calculation, but lose the association form.

Is this a bug? How can I get it evaluated with Association?

Using Mathematica V10.1 on Mac

PS: I can't loose the association structure, the real case is more complex.

Update:

ass /. a : {_, _, _} :> toISOdate[a]


Works as expected.

• If you assign the result of the Replace function to a variable, and recall it, it's correct (v 10.2 Mac OS X). a = Replace[....]; a["date"] – kale Jul 29 '15 at 23:31
• @Mr.Wizard I'm on Mac. I edited the question to add this information tks. – Murta Jul 29 '15 at 23:32

Taliesin Beynon stated in reply to Held keys in associations:

Keys have to remain unevaluated for associations to have any efficiency advantages over ordinary lists of rules. There's no way around that.

Apparently this is simply another manifestation of Replacement inside held expression and the same solution applies:

Replace[ass, a : {_, _, _} :> RuleCondition @ toISOdate[a], -2]

<|"date" -> {"2014-01-01", "2014-01-02"}|>


The question then becomes why does ReplaceAll cause evaluation? I think it should not, and I think that is a bug just as it is for Map and AssociationMap.

• RuleCondition is undocumented no? +1 – Murta Jul 30 '15 at 0:28
• @Murta Yes indeed, but very convenient. WReach introduced it to public use (at least within Stack Exchange) here, I believe. – Mr.Wizard Jul 30 '15 at 1:47
• Very interesting to know. – Murta Jul 30 '15 at 1:51
• @Mr.Wizard This feels like a bug to me... consider reporting it to Tech Support and I'll see what various other people in the company think. – Taliesin Beynon Jul 31 '15 at 4:32
• @Mr.Wizard I don't like this behavior and I've advocated against it within the company. Did you report it as a bug to Tech Support? – Taliesin Beynon Mar 19 '17 at 11:59