9
$\begingroup$

Bug introduced in 10.0.0 and fixed in 10.0.2


Is it possible to take advantage of Dataset's Query operator syntax to Merge parallel queries thereby avoiding Function's that are otherwise required?

Using the planets data:

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

{moonMasses, nMoons } = {planets[All, "Moons", Median, "Mass"], 
  planets[All, "Moons", Length, "Mass"]}

enter image description here

These queries are nearly equivalent merges:

(1) Merge[{moonMasses // Normal, nMoons // Normal}, List]

enter image description here

(2) planets[All, "Moons", {Median[#], Length[#]} &, "Mass"] // Normal

enter image description here

The values in (1) are unfortunately wrapped in an extra nested list (and further requres normalizing the data as Merge doesn't take Dataset arguments).

(2) is preferred (normalizing here only because 10.0.0 Dataset Format is not usable).

How to avoid using Function in (2), eg, to shorten the query to a syntax similar to:

planets[All, "Moons", {Median, Length}, "Mass"]
$\endgroup$
6
  • $\begingroup$ Am I wrong to understand from the documentation that your proposed short query syntax should work? $\endgroup$
    – Rojo
    Commented Jul 31, 2014 at 5:26
  • $\begingroup$ In the meantime, a subquery seems to work planets[All, "Moons", Query[{Median, Length}], "Mass"] $\endgroup$
    – Rojo
    Commented Jul 31, 2014 at 5:29
  • $\begingroup$ @Rojo, that works - I had tried {Query[Median],Query[Length]} but didn't think of this variation. Write it up as an answer, will accept. $\endgroup$ Commented Jul 31, 2014 at 5:46
  • $\begingroup$ This bug is not yet fixed in Mathematica 10.0.1 $\endgroup$
    – Mr.Wizard
    Commented Sep 17, 2014 at 13:53
  • 1
    $\begingroup$ @Mr.Wizard Seems to be fixed in 10.0.2 $\endgroup$ Commented Dec 18, 2014 at 9:25

1 Answer 1

9
$\begingroup$

Am I wrong to understand from the documentation that your proposed short query syntax should work?

In the meantime, a subquery seems to work planets[All, "Moons", Query[{Median, Length}], "Mass"]

$\endgroup$
5
  • 2
    $\begingroup$ planets[All, "Moons", {Median, Length}, "Mass"] should work, because Median and Length on their own are ascending, so {Median, Length} should clearly also be considered to be ascending. Thanks for finding! $\endgroup$ Commented Jul 31, 2014 at 17:37
  • $\begingroup$ @TaliesinBeynon are Apply, or MapIndexed given some special treatment (such as descending operators)? Because I usually find issues with them but they aren't descending $\endgroup$
    – Rojo
    Commented Aug 9, 2014 at 4:23
  • 1
    $\begingroup$ It doesn't really make sense for Map to be descending, because Map[f] is really All, f. Apply could be descending, but it's more useful for it be ascending, because it is a useful sugar on top of other ascending functions, e.g. Apply[#1 + #2&] <=> #[[1]] + #[[2]]&. Not sure about MapIndexed. $\endgroup$ Commented Aug 11, 2014 at 21:41
  • 1
    $\begingroup$ @TaliesinBeynon, makes sense, thx. So for example the fact that this doesn't work Dataset[{1}][Apply[f]] but this does Dataset[{1}][Apply[f, #] &] is a simple bug $\endgroup$
    – Rojo
    Commented Aug 11, 2014 at 22:53
  • 1
    $\begingroup$ yes, that's a bug. thanks, fixed! $\endgroup$ Commented Aug 11, 2014 at 22:59

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.