6
$\begingroup$

TimeSeries adds a TimeObject parameter and a TimeZone option to DateObjects. How can this be prevented?

DateObjects are created without either of TimeObject or TimeZone.

dat = {DateObject@{2007, 1, #}, #} & /@ Range[2]

enter image description here


Version 11

Things were slightly improved in version 11. The "Dates" property now has the dates without the polluted TimeObject.

ts = TimeSeries[dat];
ts["Dates"] // InputForm

(* {DateObject[{2007, 1, 1}], DateObject[{2007, 1, 2}]} *)

However, the "FirstDate" and "LastDate" properties still have the TimeObject pollution.

ts /@ {"FirstDate", "LastDate"} // InputForm

(* {DateObject[{2007, 1, 1}, TimeObject[{0, 0, 0.}, TimeZone -> -3.], TimeZone -> -3.],
    DateObject[{2007, 1, 2}, TimeObject[{0, 0, 0.}, TimeZone -> -3.], TimeZone -> -3.] } *)

My fingers are crossed for 11.1


Version 10.4.1

When loaded into a TimeSeries DateObjects are polluted with these addtions.

ts = TimeSeries[dat];
ts["Dates"]

enter image description here

The extras can be see from InputForm.

ts["FirstDate"] // InputForm
(* DateObject[{2007, 1, 1}, TimeObject[{0, 0, 0.}, TimeZone -> -3.], TimeZone -> -3.] *)

How can this be turned off?

$\endgroup$
  • $\begingroup$ It may be difficult to turn this off. What problem does this behavior cause? Perhaps those are easier to solve. $\endgroup$ – MarcoB Jun 7 '16 at 23:24
  • $\begingroup$ @MarcoB The issue is comparison with dates in the code. All dates in the code do not have the extra bits in them. So wherever I compare dates with the polluted TimeSeries dates I do not get equality. $\endgroup$ – Edmund Jun 8 '16 at 12:55
  • $\begingroup$ You could consider writing a custom equality test based on DateDifference[] if need be. $\endgroup$ – J. M. will be back soon Jun 9 '16 at 21:12
  • $\begingroup$ Related: mathematica.stackexchange.com/questions/78901/… $\endgroup$ – alancalvitti Jul 28 '16 at 22:35
2
$\begingroup$

I could not find a way to prevent the addition, so you might be left with cleaning up after the fact.

Depending on which side you control, you could either add the missing bits, or remove the excess.

If you want to add the missing parts:

datComplete = {DateObject[{2007, 1, #}, TimeObject[{0, 0, 0}], 
                  TimeZone -> $TimeZone], #} & /@ Range[2]

complete dates

Alternatively, if you want to clean up the output of TimeSeries:

Clear[cleanDates]
cleanDates[date_DateObject] :=
  ReplaceAll[
    date,
    DateObject[{y_, m_, d_}, ___] :> DateObject[{y, m, d}]
  ]
SetAttributes[cleanDates, Listable]

ts["Dates"]
cleanDates@ts["Dates"]

the original cleaned up

$\endgroup$
  • $\begingroup$ Yes. I capitulated to the cleaning scenario shortly after posting as work needed to continue. (1+) I don't get why WRI is added things it. It is very annoying to slap all that bloat into your data with no way of preventing it. An odd choice. $\endgroup$ – Edmund Jun 9 '16 at 20:36
  • $\begingroup$ @Edmund It certainly is! My best guess is that it has to do with the fact that interpolation will be used to fill in missing values, but still... More importantly, I'm unpleasantly surprised that the comparison fails! I'd expect that, when a comparison is called for, the missing parts in your simpler DateObjects would be filled in with appropriate default values, just like TimeSeries does! That's the unsettling bit, in my opinion. I'd otherwise be OK with the added bits, if the comparison to a simpler structure still worked automagically... $\endgroup$ – MarcoB Jun 9 '16 at 20:42

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.