7
$\begingroup$

Bug introduced in 10.0 and fixed in 10.2.0
Note: Dataset and Association are new in 10.0


Related to this question, why can't Transpose handle fractions? (Note the doc pages for Transpose hasn't been updated for v10)

Tis is ok using N:

 <|"a" -> Range[5], "b" -> (1/Range[5] // N)|> // Dataset // Transpose

But not as fractions:

 <|"a" -> Range[5], "b" -> (1/Range[5])|> // Dataset // Transpose

causes Failure with Message "the first two levels of <|a-> _, b-> _|> cannot be transposed"

$\endgroup$
  • 1
    $\begingroup$ Interestingly before the transpose <|"a" -> Range[5], "b" -> (1/Range[5])|> // Dataset doesn't format as I would expect; note the { } in the output rather than discrete columns. $\endgroup$ – Mr.Wizard May 27 '15 at 22:46
  • 1
    $\begingroup$ The bug isn't in Transpose, but in Dataset, which should figure out the right then to do here. Also note that <|"a" -> Range[5], "b" -> (1/Range[5])|> // Transpose doesn't work (and for most cases if op@data doesn't work then neither does op@Dataset@data). $\endgroup$ – Stefan R May 28 '15 at 18:53
  • $\begingroup$ @StefanR, I know, hence the tags. $\endgroup$ – alancalvitti May 29 '15 at 2:29
  • $\begingroup$ @StefanR, can you answer the other Q related to Transpose? mathematica.stackexchange.com/questions/84585/… $\endgroup$ – alancalvitti May 29 '15 at 19:28
  • 1
    $\begingroup$ This bug is fixed in Mathematica 10.2.0. $\endgroup$ – Stefan R Jul 16 '15 at 20:26
8
$\begingroup$

Following Algohi's example it seems this is another problem with the underdeveloped TypeSystem functionality behind Dataset. Look at the difference in these input forms:

Transpose @ Dataset[<|"a" -> #, "b" -> (1/#)|> & /@ Range[5]]
% // InputForm

enter image description here

Dataset[<|"a" -> {1, 2, 3, 4, 5}, 
  "b" -> {1, 1/2, 1/3, 1/4, 1/5}|>, 
 TypeSystem`Struct[{"a", "b"}, 
  {TypeSystem`Vector[TypeSystem`Atom[Integer], 5], 
   TypeSystem`Vector[TypeSystem`Atom[Rational], 
    5]}], <|"Origin" -> HoldComplete[
    AssociationTranspose, Dataset`DatasetHandle[
     261189890384722]]|>]

Note specifically TypeSystem`Vector[TypeSystem`Atom[Rational], 5].

Now the malformed case that does not transpose:

Dataset[<|"a" -> Range[5], "b" -> (1/Range[5])|>]
% // InputForm

enter image description here

Dataset[<|"a" -> {1, 2, 3, 4, 5}, 
  "b" -> {1, 1/2, 1/3, 1/4, 1/5}|>, 
 TypeSystem`Struct[{"a", "b"}, 
  {TypeSystem`Vector[TypeSystem`Atom[Integer], 5], 
   TypeSystem`Tuple[{TypeSystem`Atom[Integer], 
     TypeSystem`Atom[Rational], TypeSystem`Atom[
      Rational], TypeSystem`Atom[Rational], 
     TypeSystem`Atom[Rational]}]}], 
 <|"ID" -> 141042475246422|>]

Stefan R notes that there is a bug in the display of this form, and also in the way Transpose is handled by Dataset, but the two are unrelated. Contrary to my earlier assertion the type system behavior is not at fault. See the comments below for more.

$\endgroup$
  • $\begingroup$ The second case isn't malformed. It's a perfectly valid type, which you can verify with TypeSystem`ValidTypeQ. $\endgroup$ – Stefan R May 28 '15 at 18:57
  • $\begingroup$ Also you can use TypeSystem`ConformsQ to verify that 1/Range[5] does conform to this type. $\endgroup$ – Stefan R May 28 '15 at 19:09
  • $\begingroup$ @Stefan Thanks for the correction. Would you please explain: (1) why the second case is not formatted as columns; (2) why the transpose fails? $\endgroup$ – Mr.Wizard May 29 '15 at 3:30
  • 2
    $\begingroup$ Those are two distinct bugs. The formatting issue is benign and minor, but the transpose bug is more serious. I have reported these internally. $\endgroup$ – Stefan R May 29 '15 at 18:32
  • $\begingroup$ @Stefan Thank you, again. Would you consider answering this question yourself to provide the correct perspective? I would then delete this answer. $\endgroup$ – Mr.Wizard May 29 '15 at 18:48
3
$\begingroup$

Maybe it should be like this:

Transpose@Dataset@(<|"a" -> (1/#), "b" -> (#)|> & /@ Range[5])
$\endgroup$
  • $\begingroup$ As @Mr.Wizard mentioned as well, Transpose is likely not to be the culprit here. Something funny is going on with Dataset, or at least with the way that two essentially equivalent Dataset objects are displayed. In a way, I think that you are supporting this hypothesis, in that you show with your example that Transpose is working just fine, when given the opportunity. $\endgroup$ – MarcoB May 28 '15 at 0:25
  • $\begingroup$ @MarcoB I expanded on this in my answer below. This functionality really isn't complete yet based on all the edge cases like this that keep cropping up. $\endgroup$ – Mr.Wizard May 28 '15 at 0:30

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.