Generation and Preservation of Options to Dataset in Version 12.1
Generation and Preservation of Options to Dataset in Version 12.1
Seth J. Chandler
Version 12.1 contains many new formatting options for Dataset.
I have a dataset. I want it Yellow.
In[]:=
dataset=Dataset[{{1,0},{0,1},{1,1},{0,0},{0,1},{1,0},{1,1},{0,1},{0,1},{1,0},{0,0}},BackgroundYellow]
Out[]=
Now I want to run a Query on it.
In[]:=
q=QueryGroupBy[#[[1]]&]/*KeySort,(GroupBy[#[[2]]&])/*KeySort,&[dataset]
Length[#]
11.
Out[]=
Notice that the “Yellow” option is not inherited. That is perhaps sensible default behavior, but what if I want to preserve the options. How do I do it?
Moreover, what if I want the elements of the derived Dataset to be kept internally at their full length but presented so that they are rounded to two decimal places. I could do the following icky thing in which I go from the Dataset to Normal form and then back to Dataset.
In[]:=
q2=Dataset[Normal@q,ItemDisplayFunction(Round[#,0.01]&)]
Out[]=
Annotate doesn' t work :
In[]:=
Annotate[q,ItemDisplayFunction(Round[#,0.01]&)]
Out[]=
Annotate
,ItemDisplayFunction(Round[#1,0.01]&)
Nor does SetOptions :
In[]:=
SetOptions[q,ItemDisplayFunction(Round[#,0.01]&)]
Out[]=
SetOptions
,ItemDisplayFunction(Round[#1,0.01]&)
And again, notice that Query does not let one cause inheritance of the options . The rounding is gone.
In[]:=
Query[All,All,#/2&][q2]
Out[]=
Moreover, none of this is the fault of Query. Here’s the same code as I tried initially but performed without use of Query.
In[]:=
GroupBy[#1〚1〛&]/*MapGroupBy[#1〚2〛&]/*Map&/*KeySort/*KeySort[dataset]
Length[#1]
11.`
Out[]=
Is there a workaround. Do we need an Inheritance option for Dataset or Query?
