5
$\begingroup$

Using:

planets = ExampleData[{"Dataset", "Planets"}];

The full form of this projection displays the internal type def:

planets[1 ;; 2, KeyDrop["Moons"]] // FullForm

(* ... Assoc[Atom[String], Struct[{"Mass", "Radius"}, {Atom[1 kg]],Atom[1 km]}], AnyLength] ...*) 

Formatted:

enter image description here

Whereas projection by Span, in 2nd slot, will cast the type - known issue as per Taliesin's comments elsewhere - casts Struct to an Assoc (TypeSystem is undocumented).

planets[1 ;; 2, 1 ;; 2] // FullForm

(* ... Assoc[Atom[String], Assoc[Atom[String], AnyType, 2], AnyLength] ... *)

enter image description here

I need to go the other direction (motivation: need to re-thread Keys after Outer product which currently doesn't support Associations).

data = <|1 -> <|1 -> "a", 2 -> "b"|>, 2 -> <|1 -> "c", 2 -> "d"|>|> //
    Dataset // FullForm

(* ... Assoc[Atom[Integer], Assoc[Atom[Integer], Atom[String], 2], 2] ... *) 

Why does this fail, using Dataset constructor's 2nd argument. I think I'm using the same template except for the type specifics:

Dataset[<|1 -> <|1 -> "a", 2 -> "b"|>, 2 -> <|1 -> "c", 2 -> "d"|>|>, 
 Assoc[Atom[Integer], Struct[{1, 2}, {Atom[String], Atom[String]}], 
  AnyLength]]

(* Dataset::data: "Data does not conform to type Assoc[Atom[Integer],Struct[{1,2},{Atom[String],Atom[String]}],AnyLength]."  *) 
$\endgroup$
  • $\begingroup$ It seems it would work if 1 and 2 were strings. Btw, I don't get the types by using FullForm $\endgroup$ – Rojo Sep 24 '14 at 3:42
  • $\begingroup$ @Rojo, what do you see w/ FullForm - only the data? $\endgroup$ – alancalvitti Sep 24 '14 at 13:19
  • $\begingroup$ Sorry, I do see it, my bad $\endgroup$ – Rojo Sep 24 '14 at 13:45
6
$\begingroup$

Structs can only have string keys. That's hard to justify theoretically, but it's easy to justify practically :)

|improve this answer|||||
$\endgroup$

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.