The result we see is due to a somewhat baffling formatting decision made within the machinery that generates the box form of datasets. When formatting a date object, it uses DateString
form. However, it also expressly checks to see whether the date has three components. If so, it drops the first four characters from the string form. This is strange and I am tempted to call it a bug. It wouldn't hurt to report it to Wolfram.
Here is a direct exhibition of the problem:
Dataset`MakeAtomBox[
TypeSystem`Atom[DateObject]
, DateObject[{2007, 1, 20}, DateFormat -> {"Year", "-", "Month", "-", "Day"}]
]
(*
InterpretationBox[TagBox[TooltipBox[StyleBox["-01-20", ...], ...]
*)
Analysis (valid for version 10.4.1)
The problematic definition can be seen like this:
Block[{Dataset`RichBox = HoldForm}
, Dataset`MakeAtomBox[
TypeSystem`Atom[DateObject]
, DateObject[{2007, 1, 20}, DateFormat -> {"Year", "-", "Month", "-", "Day"}]
]
]
(*
HoldForm[
DateObject[{2007, 1, 20}, DateFormat -> ...]
, If[Length[First[DateObject[{2007, 1, 20}, DateFormat -> ...]]] == 3
, StringDrop[#1, 4] &
, Identity][DateString[DateObject[{2007, 1, 20}, ...]]
]
]
*)
or by looking for the DateObject
definition in the output of:
Dataset;
Needs["GeneralUtilities`"]
PrintDefinitions[Dataset`FormattingAtomic`PackagePrivate`abox]
Work-around
A quick fix, which will void your warranty, is to replace the problematic definition:
Dataset`FormattingAtomic`PackagePrivate`abox[DateObject, x_DateObject] :=
Dataset`RichBox[x, DateString[x]]
Giving:
Dataset[
AssociationThread[{"Date", "One", "Two"},
{DateObject[{2007, 1, 20}, DateFormat -> {"Year", "-", "Month", "-", "Day"}], 1, 2}]]
