40
votes
Accepted
Visualizing Type System Operations
This response defines a function called traceTypes which provides a quick-and-dirty visualization of type system operation. The function is somewhat fragile as it ...
40
votes
Accepted
Struggling to understand Query
Short Answer
The query operator for a given level can perform both descending and ascending actions, separated by the /* operator. We can tack the descending ...
24
votes
Accepted
Query: adding additional operator changes meaning of preceding operators
This is a corner case that occurs when ascending operators are interleaved between descending operators. This case falls into an undocumented grey area.
In the Details and Options section of the ...
14
votes
Accepted
Transpose fail in 11.1 Dataset
As observed in the question, the problem lies with the type information of the dataset. Specifically, the type information for the innermost association is missing (i.e. "any type"). This causes the ...
12
votes
Slicing an Association with named key span without normalizing?
I don't know if this is useful to you but it seems a little cleaner than your own code:
...
11
votes
Accepted
Query datasets with "variable" named slots
These work:
d[Select[#[colname] > 3 &]]
In the Details section of Slot, it is said that "# is equivalent to Slot[1]"
so it is equivalent to write:
...
11
votes
Accepted
How to filter this nested list of Association
We must adjust the Select operator to account for the fact that the keys "a" and "b" are ...
11
votes
How does Query decide the order in which the functions are applied?
@Lee's answer shows how to circumvent the problem by using RightComposition (/*) instead of ...
10
votes
Simplifying a reverse Fold for a Query
A more direct solution with Fold using Range to reverse.
With
...
10
votes
Query datasets with "variable" named slots
@SquareOne's answer shows the natural, idiomatic way to express the query. It exploits the fact that an association can be applied to a key to extract that key's value. A similar work-around would ...
10
votes
Accepted
A subtlety in Query
The behaviour is by design. When we query a Dataset, the system tries to infer whether we wish the result to be a dataset itself, or just a simple value. The ...
10
votes
Does anyone know a way to use patterns in Query?
There is no built-in facility to do this kind of transformation, but we can define our own query operator like so:
...
10
votes
Accepted
How can I understand this example of Query taken from current Mathematica documentation?
This is "ascending" sub-query operator syntax. It operates on the entire row to produce a new row with the specified keys and values as the operator applied to the row.
However, the ...
9
votes
A subtlety in Query
I'm not sure I'm missing something here, but as far as I can see, you should regard this as a feature. When you evaluate your Query, one of the later steps is to ...
9
votes
Accepted
Aggregation queries on lists of associations in 10.3
As confirmed by @Stefan R, it is a bug in 10.3.
In the meanwhile, a possible workaround is : Merge[xx, Mean]
9
votes
Accepted
Does anyone know a way to use patterns in Query?
Since I am not aware of any built-ins, here is another custom solution:
...
8
votes
Unexpected behavior of PreIncrement when querying associations
The 2nd example given under Query > Properties & Relations tells us
Before being applied, Query expressions are "compiled" into ordinary compositions of ...
8
votes
Large Dataset query fails if column contains Missing
Extended comment converted to a non-answer, nailing down what is required to trigger this bug:
Here's a simple Dataset with one key having all string values, ...
8
votes
Accepted
Query inside Dynamic triggers continuous high CPU load for FE
A quick fix is to add TrackedSymbols :> {searchstring} to the Dynamic.
But at the end it is just another example from a ...

Kuba♦
- 136k
7
votes
Accepted
Query and Dataset Syntax Peculiarities
Let's go through it blow-by-blow...
Query[DeleteMissing] @ d1
This will apply DeleteMissing to the list of associations. The documentation says:
DeleteMissing[...
7
votes
Getting slices of a nested Association via Query
This will work:
db // Query[ Drop[ #, None, {3} ]& @* Transpose, 2, 1 ;; 3 ]
{<|"English" -> "a", "Greek" -> "α"|>, <|"English" -> "b",
"Greek" -...
7
votes
Applying a function by Key pattern, preserving Association order
This should do what you want:
...
7
votes
Accepted
7
votes
Select dataset rows that meet a mathematical criterion in a column
Assuming that you intend to use a Dataset with named rows (and being aware that this means that each row must have a unique name), one way is:
...
7
votes
Accepted
How can default valued be added in a Query?
The issue is indeed that since both defaulter and Length are ascending operators, they are applied "bottom-up". That ...
6
votes
Getting slices of a nested Association via Query
@gwr led me to try Transpose after the first subquery as an ascending operator (/*).
...
6
votes
Slicing an Association with named key span without normalizing?
From version 10.4 onward, we can define keySpan like this:
...
6
votes
Accepted
Passing values from a list to Select during a Dataset query
You can use Function to proceed
myDs[Select[Or @@ (Function[id, #id == id] /@ {5, 4, 1}) &], "name"]
but there are ...

Kuba♦
- 136k
6
votes
Query inside Dynamic triggers continuous high CPU load for FE
You may use the TrackedSymbols option on either DynamicModule or Dynamic.
From the comments ...
6
votes
How to pull out the underlying query syntax being used by dataset?
We can extract the query from the dataset object through pattern-matching:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
query × 69dataset × 41
associations × 28
list-manipulation × 7
bugs × 6
function-construction × 3
filtering × 3
missing × 3
import × 2
replacement × 2
functional-style × 2
data-structures × 2
index × 2
api × 2
plotting × 1
functions × 1
front-end × 1
probability-or-statistics × 1
programming × 1
dynamic × 1
warning-messages × 1
data × 1
visualization × 1
options × 1
core-language × 1