This is relates to a bug that was introduced in 10.0.0 and fixed in 10.0.1
It also relates to an issue that has yet to be corrected.
After applying GroupBy
to a key all of whose "values"
are String
, is it possile to force the internal type representation to subsequently lookup by "value"
rather than Key@"value"
?
GroupBy
modifies internal type representation:
titanic = ExampleData[{"Dataset", "Titanic"}];
(* ... Vector[Struct[List["class", "age", "sex", "survived"],
List[Atom[Enumeration["1st", "2nd", "3rd"]], Atom[Integer],
Atom[Enumeration["female", "male"]], Atom[Boolean]]], AnyLength] ... *)
(so does Normal'izing following by casting back to Dataset though AnyLength
is replaced by a numerical value, eg 1309.)
Even though the keys (formerly values) are String:
titanic[GroupBy[Key@"sex"]][Keys, # -> Head[#] &]
(* {"female" -> String, "male" -> String} *)
This lookup fails:
titanic[GroupBy[Key@"sex"]]["female"]
(* ... Part female is not applicable to <|(Alternatives[Enumeration[female, \
male]] -> _List)..|> ... *)
Note: lookup query Key@"female"
works. Strangely, works also without Key
when KeyDrop
is applied before GroupBy
:
titanic[All, KeyDrop["survived"]][GroupBy[Key@"sex"]]["female"]
(* ... {<|"class" -> "1st", "age" -> 29, "sex" -> "female"|>, ... *)
Conversely, if Span
substitutes KeyDrop
, the data are the same
titanic[All, 1 ;; 3][GroupBy[Key@"sex"]][Keys, # -> Head[#] &]
(* {"female" -> String, "male" -> String} *)
but lookup also fails even using Key
:
titanic[All, 1 ;; 3][GroupBy[Key@"sex"]][Key@"female"]
(* ... Key Key["female"] is not one of {}. ... *)
I'm not sure how to interpret that message: b/c the internal the representation is AnyType
:
Assoc[Atom[AnyType],
Vector[Assoc[Atom[String], Atom[AnyType], 3], AnyLength], AnyLength]
How to handle these various cases uniformly?