luigi.date_interval module

luigi.date_interval provides convenient classes for date algebra. Everything uses ISO 8601 notation, i.e. YYYY-MM-DD for dates, etc. There is a corresponding luigi.parameter.DateIntervalParameter that you can use to parse date intervals.

Example:

class MyTask(luigi.Task):
    date_interval = luigi.DateIntervalParameter()

Now, you can launch this from the command line using --date-interval 2014-05-10 or --date-interval 2014-W26 (using week notation) or --date-interval 2014 (for a year) and some other notations.

class luigi.date_interval.DateInterval(date_a, date_b)[source]

Bases: object

The DateInterval is the base class with subclasses Date, Week, Month, Year, and Custom. Note that the DateInterval is abstract and should not be used directly: use Custom for arbitrary date intervals. The base class features a couple of convenience methods, such as next() which returns the next consecutive date interval.

Example:

x = luigi.date_interval.Week(2013, 52)
print x.prev()

This will print 2014-W01.

All instances of DateInterval have attributes date_a and date_b set. This represents the half open range of the date interval. For instance, a May 2014 is represented as date_a = 2014-05-01, date_b = 2014-06-01.

dates()[source]

Returns a list of dates in this date interval.

hours()[source]

Same as dates() but returns 24 times more info: one for each hour.

prev()[source]

Returns the preceding corresponding date interval (eg. May -> April).

next()[source]

Returns the subsequent corresponding date interval (eg. 2014 -> 2015).

to_string()[source]
classmethod from_date(d)[source]

Abstract class method.

For instance, Month.from_date(datetime.date(2012, 6, 6)) returns a Month(2012, 6).

classmethod parse(s)[source]

Abstract class method.

For instance, Year.parse("2014") returns a Year(2014).

class luigi.date_interval.Date(y, m, d)[source]

Bases: DateInterval

Most simple DateInterval where date_b == date_a + datetime.timedelta(1).

to_string()[source]
classmethod from_date(d)[source]

Abstract class method.

For instance, Month.from_date(datetime.date(2012, 6, 6)) returns a Month(2012, 6).

classmethod parse(s)[source]

Abstract class method.

For instance, Year.parse("2014") returns a Year(2014).

class luigi.date_interval.Week(y, w)[source]

Bases: DateInterval

ISO 8601 week. Note that it has some counterintuitive behavior around new year. For instance Monday 29 December 2008 is week 2009-W01, and Sunday 3 January 2010 is week 2009-W53 This example was taken from from http://en.wikipedia.org/wiki/ISO_8601#Week_dates

Python datetime does not have a method to convert from ISO weeks, so the constructor uses some stupid brute force

to_string()[source]
classmethod from_date(d)[source]

Abstract class method.

For instance, Month.from_date(datetime.date(2012, 6, 6)) returns a Month(2012, 6).

classmethod parse(s)[source]

Abstract class method.

For instance, Year.parse("2014") returns a Year(2014).

class luigi.date_interval.Month(y, m)[source]

Bases: DateInterval

to_string()[source]
classmethod from_date(d)[source]

Abstract class method.

For instance, Month.from_date(datetime.date(2012, 6, 6)) returns a Month(2012, 6).

classmethod parse(s)[source]

Abstract class method.

For instance, Year.parse("2014") returns a Year(2014).

class luigi.date_interval.Year(y)[source]

Bases: DateInterval

to_string()[source]
classmethod from_date(d)[source]

Abstract class method.

For instance, Month.from_date(datetime.date(2012, 6, 6)) returns a Month(2012, 6).

classmethod parse(s)[source]

Abstract class method.

For instance, Year.parse("2014") returns a Year(2014).

class luigi.date_interval.Custom(date_a, date_b)[source]

Bases: DateInterval

Custom date interval (does not implement prev and next methods)

Actually the ISO 8601 specifies <start>/<end> as the time interval format Not sure if this goes for date intervals as well. In any case slashes will most likely cause problems with paths etc.

to_string()[source]
classmethod parse(s)[source]

Abstract class method.

For instance, Year.parse("2014") returns a Year(2014).