13

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} &]
alancalvitti
  • 15,143
  • 3
  • 27
  • 92

1 Answers1

16

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'!

Taliesin Beynon
  • 10,639
  • 44
  • 51