7
$\begingroup$

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....)

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Mr.Wizard Dec 13 '14 at 19:32
4
$\begingroup$

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
$\endgroup$
  • $\begingroup$ How exactly do those paclet updates work and is there a way to tell which sub-sub-version one is running? $\endgroup$ – Mr.Wizard Dec 15 '14 at 17:44
  • $\begingroup$ @Mr.Wizard I don't know but check PacletInformation["Dataset"] $\endgroup$ – Rojo Dec 16 '14 at 13:45
  • $\begingroup$ 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? $\endgroup$ – Mr.Wizard Jan 14 '15 at 1:31
1
$\begingroup$

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
$\endgroup$
0
$\begingroup$

Workaround: Use Normal to unpack the dataset before prepending:

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

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.