6
$\begingroup$

I'm in version 10.0.1 using a Dataset to do some plots and things. For one of the plots I need to get the minimum date of a some filtered set of the Dataset. I can get this set of DateObjects without any issues and add the Min operator in the Dataset. However, Min in the Dataset does not return if the list gets too big.

I worked out that it is the Min function that is the issue.

This returns immediately.

DateRange[DateObject[{2000, 1, 1}], DateObject[{2000, 10, 1}], "Month"] // Min

However, add more dates and it never returns.

DateRange[DateObject[{2000, 1, 1}], DateObject[{2014, 10, 1}], "Month"] // Min

Is this a bug or am I doing something wrong here? I don't know how many records will return before I apply the filter on the Dataset. Nor do I know what the minimum of the filtered set will be.

Is there perhaps a workaround using a Dataset? If it is a bug, how do I report it?

Thanks,

Edmund

$\endgroup$

2 Answers 2

6
$\begingroup$

Use AbsoluteTime :-

DateObject[Min[Map[AbsoluteTime,
   DateRange[DateObject[{2000, 1, 1}],
    DateObject[{2014, 10, 1}], "Month"]]]]
$\endgroup$
3
  • $\begingroup$ Ok, I've tried it with Normal /* Min /* DateObject@testDateMin[All, "Date", AbsoluteTime] and it returns immediately. I wonder why they are not converting with AbsoluteTime in Min for ``_DateObjectQ`. Thanks for the workaround. $\endgroup$
    – Edmund
    Oct 26, 2014 at 14:32
  • $\begingroup$ @Chris 10.3.1 on my computer, when evaluated on DateObject[{10, 12, 1}], DateObject[{2014, 10, 1}] - note starts w year ten, so ~20k objects - your workaround doens't seem faster than wrapping in //Dataset//Min. In fact, //Length takes almost as long, prelim timing studies. $\endgroup$ Dec 30, 2015 at 18:57
  • $\begingroup$ @alancalvitti Yes, something seems to have been improved. The OP's version works fast now. $\endgroup$ Dec 30, 2015 at 19:24
4
$\begingroup$

Consider also 'Sort' and 'First'

>  (your expression here...) // Sort // First

Max also suffers poor performance on DateObjects that can remedied in similar form:

> (your expression here...)  //Sort // Last

To comment on the OP situation: at this time (MMA 10.0.2) short lists also suffer unacceptable delays. For example, applying Min or Max to a list of 16 elements takes 17 seconds in my system, whereas the First @ Sort (or Sort // First) forms take about 3 milliseconds.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.