7
$\begingroup$

A Dataset object has internal metadata. For example, let

ds = Dataset[{<|"a" -> 1, "b" -> "x", "c" -> {1}|>}];

Then, after re-formatting for legibility,

FullForm[ds]

shows this:

Dataset[
 List[
  Association[
   Rule["a",1],
   Rule["b","x"],
   Rule["c",List[1]]
  ]
 ],
 TypeSystem`Vector[
  TypeSystem`Struct[
   List["a","b","c"],
   List[
    TypeSystem`Atom[Integer],
    TypeSystem`Atom[String],
    TypeSystem`Vector[
     TypeSystem`Atom[Integer],
     1
    ]
   ]
  ],
  1
 ],
 Association[Rule["ID",204779820583110]]
]

One can't, however, access the parts of this expression in the usual way (i.e. using Part). For example, ds[[3]] evaluates to

Mathematica graphics

Also, one can't change the head of the Dataset object the usual way (i.e. using Apply): Head[List @@ ds] evaluates to Dataset, not List.


Questions:

  1. How can one access the internal parts of a Dataset object programmatically?
  2. What other general Mathematica rules fail to hold when it comes to Dataset objects?
  3. Where in the Mathematica documentation are the answers to the previous two questions to be found?

$\endgroup$
  • 2
    $\begingroup$ ds is AtomQ. Just try AtomQ@ds. ds[[3]] is like (1/2)[[1]]. (FullForm[1/2] is Rational[1, 2]). $\endgroup$ – Karsten 7. May 16 '16 at 19:52
  • 3
    $\begingroup$ There should be some useful functions for this job in Needs["TypeSystem`"]; Names["TypeSystem`*"] and Needs["Dataset`"]; Names["Dataset`*"]. Most of these are probably undocumented. $\endgroup$ – Karsten 7. May 16 '16 at 20:01
7
$\begingroup$

Starting with the same Dataset as m_goldberg in his answer

ds = Dataset[{<|"a" -> 1, "b" -> "x", "c" -> {1/2}|>, 
              <|"a" -> 2, "b" -> "y", "c" -> {"a", {}, 1/2}|>}]

The same information can be extracted using

Needs["Dataset`"] 
GetData@ds
GetRawData@ds
GetType@ds
ToDatasetHandle@ds

dsInfo

One can get all these information at once using

DatasetPart@ds

DatasetPart@ds

$\endgroup$
  • $\begingroup$ The DatasetHandle or "ID" is unique to each Dataset, therefore everyone will have a different one and it'll change after reevaluating the definition of ds. $\endgroup$ – Karsten 7. May 16 '16 at 23:55
4
$\begingroup$

This is what I able to extract.

ds = 
  Dataset[
    {<|"a" -> 1, "b" -> "x", "c" -> {1/2}|>, 
     <|"a" -> 2, "b" -> "y", "c" -> {"a", {}, 1/2}|>}]

ds

{data, types, id} = 
  ToExpression[StringReplace[ToString @ FullForm[ds], "Dataset" -> "List"]];

Dataset[data]

ds

types

types

which has the raw input form

TypeSystem`Vector[
  TypeSystem`Struct[
    {"a", "b", "c"}, 
    {TypeSystem`Atom[Integer], TypeSystem`Atom[String], 
      TypeSystem`Vector[TypeSystem`AnyType, TypeSystem`AnyLength]}],
  2]
id

<|"ID" -> 125700882739855|>

I think it is interesting that code editor has special formatting for the type metadata.

$\endgroup$
  • $\begingroup$ The special formatting for the type metadata comes with a nice Tooltip and CellPrint after clicking feature. $\endgroup$ – Karsten 7. May 17 '16 at 0:07

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.