17
$\begingroup$

Bug introduced in 10.3.0 and fixed in 10.3.1
Bug introduced in 10.3.0 and fixed in 10.4.0

First bug, see first part of the question
Second bug, see update part


Some aggregation queries applied to a list of associations (or Dataset's with this structure) lock up the front end or crash the kernel in Version 10.3.

xx = {<|"a" -> 1|>, <|"a" -> 3|>};
Mean[xx]
(* locked up front end, with cell bracket highlighted as evaluating *)

The behavior is observed in Mathematica 10.3 on OS X El Capitan. It is not observed in 10.2. A bug report has been sent to Wolfram support, and I will update this post and tag it appropriately when I get a reply.

In the meantime, we are fortunate that Total still works, so my workaround is

myMean[listofassoc:{_Association..}] :=Total[listofassoc]/Length[listofassoc];
myMean[args___]:=Mean[args];

Note that the above code does not catch the Dataset case.

Update: As pointed out in the comments, this bug only occurs when the associations contain single items, so

Mean[{<|"a" -> 1, "b" -> 2|>, <|"a" -> 3, "b" -> 12|>}]

(* <|"a" -> 2, "b" -> 7|> *)

However, when the list contains a single association, a list is returned instead of a singleton

Mean[{<|"a" -> 1, "b" -> 2|>}]

(* {<|"a" -> 1, "b" -> 2|>} *)

which is unexpected behavior, and also different from 10.2 behavior.

$\endgroup$
  • $\begingroup$ Same for me with OSX 10.9.5 and MMA v10.3. Plus@@listofassoc also works. $\endgroup$ – SquareOne Oct 30 '15 at 16:35
  • $\begingroup$ Seen it on OS X 10.9.5 here, as well, and a colleague saw it on Linux and Windows 7. I'm marking it as a bug. $\endgroup$ – Pillsy Oct 30 '15 at 16:43
  • 4
    $\begingroup$ It's a bug in Mathematica 10.3. We are aware of the issue. $\endgroup$ – Stefan R Oct 30 '15 at 16:56
  • 2
    $\begingroup$ Another workaround: Merge[xx, Mean] $\endgroup$ – SquareOne Oct 30 '15 at 17:39
  • 1
    $\begingroup$ The remaining issue has been fixed in the development version today. $\endgroup$ – ilian Jan 15 '16 at 19:10
9
$\begingroup$

As confirmed by @Stefan R, it is a bug in 10.3.

In the meanwhile, a possible workaround is : Merge[xx, Mean]

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.