The following works:

MapIndexed[List]@{1, 2, 3}
(* {{1, {1}}, {2, {2}}, {3, {3}}} *)

This works too:

Dataset[{1, 2, 3}][MapIndexed[f]]

Mathematica graphics

Why does this not work?

Dataset[{1, 2, 3}][MapIndexed[List]]

Mathematica graphics

This works fine again:

Dataset[{1, 2, 3}][MapIndexed[{##} &]]

Mathematica graphics

  • 1
    $\begingroup$ This looks like a bug to me $\endgroup$
    – Rojo
    Aug 6 '14 at 1:11
  • $\begingroup$ Dataset[{1, 2, 3}][MapIndexed[List[##] &]] $\endgroup$
    – m_goldberg
    Aug 6 '14 at 1:59
  • $\begingroup$ This is very similar to the issue discussed in a this question. $\endgroup$
    – m_goldberg
    Aug 6 '14 at 2:03
  • $\begingroup$ Similar to Dataset[{True}][Apply[And]]. I wonder if we are missing something $\endgroup$
    – Rojo
    Aug 7 '14 at 5:32

Could it have something to do with Dataset type checking? The Failure object contains the following details.

<|"MessageTemplate" :> Dataset::invalid, "MessageParameters" -> <|"Head" -> List,
 "Arguments" -> {TypeSystem`Atom[Integer], TypeSystem`ZSignatures`PackagePrivate`i}|>|>

The problem does not occur if MapIndexed[List] is part of a composition:

Dataset[{1, 2, 3}][MapIndexed[List] /* f]

f[{{1, {1}}, {2, {2}}, {3, {3}}}]

(It does not return a dataset presumably because the final form is not structured data. According to the Dataset documentation this means "a list or association or nested combinations of these".)

The Failure message does not seem to be from any operation that has failed, but instead seems to be from an extra check. Specifically,

Dataset[{1, 2, 3}][MapIndexed[List], FailureAction -> "Drop"] 

returns a dataset with the expected entries:

enter image description here


 Dataset[{1, 2, 3}][MapIndexed[Inactive[List]]]

returns a result as expected:

enter image description here

Intriguingly (to me), the following works and returns a Dataset:

Dataset[{1, 2, 3}][MapIndexed[Inactive[List]] /* Activate]

The following also works:

Dataset[{1, 2, 3}][MapIndexed[List] /* Dataset]

I look forward to a more complete answer.


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.