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:


(* ... 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:

 Vector[Assoc[Atom[String], Atom[AnyType], 3], AnyLength], AnyLength]

How to handle these various cases uniformly?


2 Answers 2


The main issue here is already fixed in 10.0.1 (probably as a side-effect of fixes for some of the other typesystem bugs that have already been reported by you and others!).

The span issue is separate, I've reported that (thanks!)

  • 1
    $\begingroup$ Should we tag this question as a bug in that case? $\endgroup$
    – Mr.Wizard
    Commented Aug 26, 2014 at 8:37
  • $\begingroup$ @Mr.Wizard sure. How does one do that? $\endgroup$ Commented Aug 26, 2014 at 20:08
  • $\begingroup$ If you "hover" the mouse pointer next to the existing tags, which presently are dataset and query you should see "edit tags" appear. If you click that you can edit the tags. I shall add bugs now. Please add this tag to any question/report about a confirmed bug that you see. $\endgroup$
    – Mr.Wizard
    Commented Aug 27, 2014 at 0:17

Until this bug is fixed, a work-around is to avoid the operator form of GroupBy, e.g.:

titanic[GroupBy[#, Key@"sex"]& /* "female"]

dataset screenshot

This same bug affects many operator forms, but this work-around frequently dodges it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.