7

fixed in 10.1 (windows)


I just experience a problem in prepending columns to a dataset. I did this a hundred times in 10.0.1.0 - no problems. Now it seems as if it is only possible to append/prepend one column at a time.

dataset = Dataset[{
   <|"a" -> 1, "b" -> "x", "c" -> {1}|>,
   <|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>,
   <|"a" -> 3, "b" -> "z", "c" -> {3}|>,
   <|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>,
   <|"a" -> 5, "b" -> "y", "c" -> {5, 6, 7}|>,
   <|"a" -> 6, "b" -> "z", "c" -> {}|>}]

Then:

Prepend[#, "First" -> "one"] & /@ dataset

works fine, but

Prepend[#, {"First" -> "one", "Second" -> "two"}] & /@ dataset

gives an error message:

Expression of the form Prepend[SkeletonForm[Struct[{a, b, c},
{Atom[Integer],  Atom[String], Vector[Atom[Integer], AnyLength]}],
{weakEval2[First -> one],  weakEval2[Second -> two]}]] cannot be
evaluated.

Can anyone give me a hint, if I´m doing wrong (but it worked fine ´til yesterday wen 10.0.2.0 came....)

Nasser
  • 143,286
  • 11
  • 154
  • 359
mgamer
  • 5,593
  • 18
  • 26
  • It seems like a bug to me since it works on Association expressions and since the error message is weird, but I'll wait for consensus or confirmation before adding the bugs tag. – Mr.Wizard Dec 13 '14 at 19:32

3 Answers3

4

This is a bug in 10.0.2 that will be fixed in 10.0.3 (if not earlier, and pushed out via a paclet update), but for now you can use this 'indirection' workaround:

prepender[x_] := Prepend[x, {"First" -> "one", "Second" -> "two"}];
prepender /@ dataset
Taliesin Beynon
  • 10,639
  • 44
  • 51
  • How exactly do those paclet updates work and is there a way to tell which sub-sub-version one is running? – Mr.Wizard Dec 15 '14 at 17:44
  • @Mr.Wizard I don't know but check PacletInformation["Dataset"] – Rojo Dec 16 '14 at 13:45
  • Tali, would you give attention to this if you have time? Is this behavior something that could realistically be changed at this time or would it break things? – Mr.Wizard Jan 14 '15 at 01:31
1

Fixed in 10.1 (windows):

Mathematica graphics


Mathematica graphics

code

dataset = Dataset[{<|"a" -> 1, "b" -> "x", "c" -> {1}|>, <|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>, <|"a" -> 3, "b" -> "z", 
    "c" -> {3}|>, <|"a" -> 4, "b" -> "x", "c" -> {4, 5}|>, <|"a" -> 5, "b" -> "y", "c" -> {5, 6, 7}|>, <|"a" -> 6, "b" -> "z", 
    "c" -> {}|>}]
Prepend[#, {"First" -> "one", "Second" -> "two"}] & /@ dataset
Nasser
  • 143,286
  • 11
  • 154
  • 359
0

Workaround: Use Normal to unpack the dataset before prepending:

Prepend[#,{"First"->"one","Second"->"two"}]& /@ Normal@dataset // Dataset
sakra
  • 5,120
  • 21
  • 33
  • I use a similar workaround, but the behavior shown above is buggy, isn´t it? – mgamer Dec 13 '14 at 14:48
  • Looks like a bug to me but modification of a dataset with Prepend and Append does not seem to be documented. – sakra Dec 13 '14 at 16:02