Simple dataset query

How about

 ds = Dataset[Table[<|"a" -> n|>, {n, 3}]];
 ds[All, "a", # + 1 &]

ds

BTW, you 1st query can be simplified to

ds[All, "a"]

This behavior is concerned with Association's HoldAllComplete attribute.

Attributes[Association]
{HoldAllComplete, Protected}

I am not completely certain of the internal workings but it appears that the a# + 1 expression is being held unevaluated when passed to Part. Wrapping the expression in Evaluate to force evaluation does not appear to help.

dataset[All, Range[4][[Evaluate[#a + 1]]] &]

Message: Plus[1, Atom[Integer]] is not a valid part specification.

However, you there is a workaround by passing the expression as a parameter to a pure function.

dataset[All, Range[4][[#]] &@(#a + 1) &]

enter image description here

Hope this helps.

Tags:

Dataset

Query