meridian.model.spec.DateRange

A date range [start_date, end_date] with both bounds inclusive.

This matches the convention used throughout Meridian's other date selection APIs -- notably TimeCoordinates.get_selected_dates and expand_selected_time_dims -- so that the same pair of dates selects the same time periods wherever it is used.

Either bound may be omitted to leave that side open. An omitted bound is resolved against the input data when the range is compiled, not at construction time, so the same DateRange may cover different dates for different datasets:

  • DateRange(start, None): from start through the last date in the data.
  • DateRange(None, end): from the first date in the data through end.
  • DateRange(): the entire date range of the data. This is the identity range; specifying it is equivalent to applying no date restriction at all.

A range whose bounds are equal is valid and selects that single date.

A bound that is present must name one of the input data's time coordinates exactly; a bound falling between two coordinates is rejected. Because it depends on the data, the check happens when the range is compiled against an InputData, not at construction time.

The mmm.v1.common.DateInterval proto that these specs serialize to uses the opposite, half-open [start_date, end_date) convention. The conversion between the two is performed in the serialization layer, which is the only place the two conventions meet.

start_date The start date (inclusive). Can be a datetime.date, datetime.datetime, np.datetime64, or an ISO-formatted string ('YYYY-MM-DD'). If None, implies all dates up to end_date.
end_date The end date (inclusive). Can be a datetime.date, datetime.datetime, np.datetime64, or an ISO-formatted string ('YYYY-MM-DD'). If None, implies all dates from start_date onwards.
date_interval Returns a normalized, inclusive (start_date, end_date) tuple.

Methods

from_date_interval

View source

Creates a DateRange from a time_coordinates.DateInterval tuple.

The tuple is interpreted with both bounds inclusive, the convention TimeCoordinates.get_selected_dates uses. It is therefore not interchangeable with the half-open mmm.v1.common.DateInterval proto of the same name.

Args
date_interval An inclusive (start_date, end_date) tuple.

Returns
The equivalent DateRange.

__eq__

Return self==value.

end_date None
start_date None