Given:
titanic = ExampleData[{"Dataset", "Titanic"}]
Why does this correctly delete Missing[] elements:
titanic[GroupBy@Key@"class", DeleteMissing[#, 1] &, "age"] // Normal
but not the default level spec? Seems to violate key transparency in Associations/Datasets
.
titanic[GroupBy@Key@"class", DeleteMissing, "age"] // Normal
(* <|"1st" -> {29, 1, 2, 30, 25, 48, 63, 39, 53, 71, 47, 18, 24, 26, 80,
Missing[], 24, 50, 32,... |> *)
DeleteMissing
also works on the bare list, as would any function applied at that Dataset slot. On the other hand:
<| "key" -> {29, 1, 2, 30, 25, 48, 63, 39, 53, 71, 47, 18, 24, 26, 80,
Missing[], 24, ... |> // DeleteMissing[#, 2] &
Level 2 is the minimum needed to delete missing element?
Answer
UPDATE The described behaviour is not a bug as DeleteMissing
is explicitly listed as a descending operator in the documentation. See the response by @TaliesinBeynon.
I will delete this response after the "accept" has been transferred.
Original Response - WARNING: The following analysis is incorrect.
This is yet another manifestation of the WRI-confirmed bug encountered here and here.
Correct compilation, with DeleteMissing
applied at the right time and level:
Dataset`CompileQuery @ Query[GroupBy@Key@"class", DeleteMissing[#,1]&, "age"]
(* Dataset`WithOverrides@*GeneralUtilities`Checked[
GroupBy[Key[class]] /*
Map[Map[GeneralUtilities`Slice[age]] /* (DeleteMissing[#1,1]&)]
, Identity
] *)
Incorrect compilation, with DeleteMissing
applied too early:
Dataset`CompileQuery @ Query[GroupBy@Key@"class", DeleteMissing, "age"]
(* Dataset`WithOverrides@*GeneralUtilities`Checked[
GroupBy[Key[class]] /*
Map[DeleteMissing /* Map[GeneralUtilities`Slice[age]]]
, Identity
] *)
Comments
Post a Comment