7
$\begingroup$

I did not understand the concepts ascending and descending in the context of the order of operations on Datasets. It is listed in the documentation, on Dataset's page and yet I did not understand. Perhaps a reference to a place that has a more detailed explanation of this topic will suffice. Thanks.

$\endgroup$
3
  • $\begingroup$ From the documentation "A descending operator is applied to corresponding parts of the original dataset, before subsequent operators are applied at deeper levels." So ascending an descending operators behavior depends on the order, the sequence in which the operators are involved. $\endgroup$
    – mgamer
    Apr 7 '20 at 16:42
  • 1
    $\begingroup$ also see Struggling to understand Query $\endgroup$
    – WReach
    Apr 8 '20 at 1:39
  • $\begingroup$ Thank you WReach!!! your comment was very important for me $\endgroup$
    – Dani
    Apr 14 '20 at 15:40
8
$\begingroup$

I'll bite. Let's play with the "Planets" dataset, as it offers a great example of nesting.

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

enter image description here

Descending operators

Part operators such as All and "key" are descending operators, which means that the next operator will be applied at a nested level. Compare:

planets[Length]
(* 8 *)

as we have 8 rows in our dataset. Length here is applied to the whole dataset.

In the next expression, All descends one level down, so now Length is applied individually to each row. Since every row of the above dataset is an association with three keys - Mass, Radius, and Moons, the result is 3 for every row:

planets[All, Length]

enter image description here

Let's keep descending. In the next expression, "Moons" descends one more level, into the list of individual planets, so now Length operates at this level and returns the number of moons per planet:

planets[All,"Moons",Length]

enter image description here

Ascending operators

Any function, such as Length above, is ascending, which means that it does not descend and operates at the current level. However, one other important feature is that an ascending operator is applied after all subsequent ascending and descending operators have been applied to deeper levels.

Consider the difference between

planet[All,"Moons",Total]

which aggregates every parameter in Moon column with Total,

enter image description here

versus

planet[All, "Moons", Total, "Mass"]

Here, Total is applied after the following "Mass" descending operator selects just that column.

enter image description here

$\endgroup$
2
  • 4
    $\begingroup$ This brings me closer to understanding the distinction (+upvote). $\endgroup$ Apr 7 '20 at 18:50
  • $\begingroup$ Thank you for the compliment, Daniel, that means a lot coming from you! $\endgroup$
    – Victor K.
    Apr 7 '20 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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