13
$\begingroup$

Bug introduced in 10.0.2 and fixed in 10.0.3


In 10.0.2

ExampleData[{"Dataset", "Titanic"}][All, <| "gender" -> #sex|> &]

Outputs the expected result, but also throws:

MapAt::partw: Part {1,All,2} of Association[gender->Atom[Enumeration[female,male]]] does not exist.

Whereas all is ok with:

ExampleData[{"Dataset", "Titanic"}][All, {"gender" -> #sex} &]
$\endgroup$
  • $\begingroup$ I get the same. If you want to use Associations the following seems to work: ExampleData[{"Dataset", "Titanic"}][All, Association[{"gender" -> #sex}] &] $\endgroup$ – Sjoerd C. de Vries Dec 11 '14 at 21:44
  • $\begingroup$ I get the same in V10.0.2 for MAC $\endgroup$ – Murta Dec 11 '14 at 22:34
16
$\begingroup$

This is a bug in the 10.0.2 version of the type inferencer, which now goes inside pure functions†.

It's 'harmless' in that the type inference will just give up and fall back on deduction (which is what it was going to do anyway).

I've fixed this for version 10.0.3, but in the meantime, here's a patch that will prevent the message:

Begin["TypeSystem`Inference`PackagePrivate`"];
exprType[e_Association] := If[AssociationQ[Unevaluated[e]], Struct@MapUn[exprType, e], TypeSystem`UnknownType];
End[];

You can safely put this in your init.m so it gets applied to all new kernels -- it won't slow anything down.

P.S. Perhaps we should have an 'errata' mechanism that allows us to apply micropatches like this via paclet download after a version has shipped. That would be nice.

† here is an example of type inference going into pure functions:

<< TypeSystem`
t = Type[<|"x" -> Integer, "y" -> Real|>]
Function[#x + #y] ** t
Function[#x + #y + #z] ** t

Edit: thanks for finding and 'reporting'!

$\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.