# Setting and changing MetaInformation for arbitrary objects

I work with a lot of dynamic data in {{date, datum}. . .} format,

datedatalist={{{2001, 1, 1}, 45.2}, {{2002, 1, 1}, 132.}, {{2003, 1, 2}, 121.1}};


and I have historically attached a header to each object in a format like

datedataObject={{header version, data series name, type (value, % change, etc.)}, datedatalist};


I can see advantages to using Mathematica's TemporalData[] type, and to using MetaInformation[] for recording the header. I would set this up with something like

newObject = TemporalData[datedatalist, MetaInformation -> {"name" -> "whatever", "type" -> "value"}];


and extract header items with, for example

newObject["name"]


But this leaves me with two puzzles,

1. How do I add MetaInformation after the object has been created? and
2. How do I change existing MetaInformation?

datedatalist={{{2001, 1, 1}, 45.2}, {{2002, 1, 1}, 132.}, {{2003, 1, 2}, 121.1}};
ct = TemporalData[datedatalist, MetaInformation -> {"name" -> "whatever", "type" -> "value"}];


Modify its meta information

ct=TemporalData[ct, MetaInformation->{"name"->"Johnny", "fat"->True}];
ct["MetaInformation"]
(* {"name" -> "Johnny", "fat" -> True, "type" -> "value"} *)

• Very nice. How did you figure that out? – Michael Stern Jul 24 '14 at 10:36
• @MichaelStern luck. I just felt it was sensible for nested temporal data's to be flattened out, tried it and worked. – Rojo Jul 24 '14 at 13:52
• To make this more general I would suggest to use the information contained in the first part of the TemporalData object. For example, addMetaInformation[ td_, metarules_ ] := Which[ td[[1]] === TimeSeries, TimeSeries[ td, MetaInformation -> metarules], ...=== EventSeries, EventSeries[...], True, TemporalData[ td, MetaInformation -> metarules ]. Also one might define addMetaInformation[ td_, None] := td /. (MetaInformation -> _) :> Sequence[]. – gwr Jul 8 '15 at 11:57

I sure hope there is a cleaner way to get both tasks than the following which is based on accessing and changing Parts of a temporal data object:

 s = Accumulate[
RandomInteger[{-5, 1}, 10]~Join~RandomInteger[{-1, 5}, 10]];
td = TemporalData[s, {1, 20}];
td["Properties"]
(* {"Part","Path","PathComponents","PathCount","PathFunction",
"PathFunctions","PathLengths","Paths","PathStates","PathTimes",
"Properties","SliceData","SliceDistribution","StateDimensions",
"States","Times"} *)


Add MetaInformation:

 td[[2, -1]] = AppendTo[td[[2, -1]], MetaInformation -> {"Event" -> 10}];
td["Properties"]
(* {"Event","Part","Path","PathComponents","PathCount","PathFunction",
"PathFunctions","PathLengths","Paths","PathStates","PathTimes",
"Properties","SliceData","SliceDistribution","StateDimensions",
"States","Times"} *)

td["Event"]
(* 10 *)


Change the value of a MetaInformation element:

 d[[2, -1, 1, 2, 1, 2]] = 20;
td["Event"]
(* 20 *)


Add another MetaInformation element:

 td[[2, -1, 1, 2]] = AppendTo[td[[2, -1, 1, 2]], "name" -> "abc"];
td["MetaInformation"]
(*{"Event" -> 20,"name" ->"abc"} *)
td["name"]
(* "abc" *)


Note: This approach works in version 9.0.1.0. Version 10 seems to have quite a few new features related to TemporalData. However, documentation information related to MetaInformation has not changed.

• This works in V10, not in V9: td = TemporalData[td, "MetaInformation" -> {"Event" -> 20}] – Michael E2 Jul 15 '14 at 1:15
• @MichaelE2, right. MetaInformation->..." (without string quotes) also works in Version 10. Although documentation on MetaInformation says the values can be changed using SetOptions it does not work for TemporalData. And, although MetaInformation is listed as an Option for TemporalData, Options[td] gives {}; and one needs to use td["Options"] to get MetaInformation -> {...}. – kglr Jul 15 '14 at 1:49
• Yes, the quotes were a typo that happened to work. – Michael E2 Jul 15 '14 at 2:37
• I think the ultimate solution will have to come from Wolfram, but I appreciate the kludge in the meantime. – Michael Stern Jul 17 '14 at 13:58

David Reiss came up with a nice kludge over in the Wolfram Communities --

newObject = newObject /. {("name" -> _) :> ("name" -> "Happy feet")}


changes the "name" part of the MetaInformation in newObject. And

newObject =
newObject /. {(MetaInformation -> x_) :> (MetaInformation -> Flatten[{x, "another" -> "Something"}])}


adds the "another" -> "Something" rule to the MetaInformation of newObject.

This does seem like a bug in Mathematica though; the behavior is illogical and at odds with the documentation.

• Seems to me that if designed "properly" it should work with SetOptions and also probably CurrentValue (analogous to how TaggingRules` works). I wonder if this is a bug or intentional? Have you asked tech support about this? – Mike Honeychurch Jul 16 '14 at 1:43
• I reported this as a bug. They haven't responded, but I don't think I ever get responses to bug reports. – Michael Stern Jul 16 '14 at 2:00
• They never use the word "bug" but normally I get a reply saying that it has been forwarded to developers and I'll be emailed when an update occurs ...or words to that effect. – Mike Honeychurch Jul 16 '14 at 2:24
• I had an exchange with tech support and provided them with a detailed notebook. They have "reported this issue into [their] database." – Michael Stern Jul 17 '14 at 17:06
• @MikeHoneychurch Hah. Tech support says that this behavior is "by design." I asked them to record it as a bug anyway. – Michael Stern Jul 18 '14 at 21:19