5

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]."  *) 
alancalvitti
  • 15,143
  • 3
  • 27
  • 92

1 Answers1

7

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

Taliesin Beynon
  • 10,639
  • 44
  • 51