Join the newly launched
Discord community for real-time discussions, peer support, and direct interaction with the Meridian team!
meridian.data.time_coordinates.TimeCoordinates
Stay organized with collections
Save and categorize content based on your preferences.
A wrapper around time coordinates in Meridian's input data.
meridian.data.time_coordinates.TimeCoordinates(
datetime_index: pd.DatetimeIndex
)
Meridian models store time coordinates as untyped strings. It treats them as
labels, and they have no intrinsic meaning to the model other than the
assumption that they represent some linearly increasing time coordinates.
This wrapper object performs some additional validation and methods for
extracting values out of these time coordinates which are treated as numeric
"date" values.
Attributes |
datetime_index
|
The given time coordinates, parsed as indexable
DatetimeIndex.
|
all_dates
|
The given time coordinates, as a list of Pythonic datetime.date
objects.
|
all_dates_str
|
The given time coordinates, as a list of Meridian-formatted
date strings. This can be used for the model internals, which treat time
coordinates as simple labels.
|
interval_days
|
Returns the mean interval between two neighboring dates in all_dates.
|
Methods
expand_selected_time_dims
View source
expand_selected_time_dims(
start_date: meridian.data.time_coordinates.Date = None,
end_date: meridian.data.time_coordinates.Date = None
) -> (list[datetime.date] | None)
Validates and returns time dimension values based on the selected times.
If both start_date and end_date are None, returns None. If specified,
both start_date and end_date are inclusive, and must be present in the
time coordinates of the input data.
| Args |
start_date
|
Start date of the selected time period. If None, implies the
earliest time dimension value in the input data.
|
end_date
|
End date of the selected time period. If None, implies the
latest time dimension value in the input data.
|
| Returns |
A list of time dimension values (as datetime.date objects) in the input
data within the selected time period, or do nothing and pass through
None if both arguments are None, or if start_date and end_date
correspond to the entire time range in the input data.
|
| Raises |
ValueError if start_date or end_date is not in the input data's time
dimension coordinates.
|
from_dates
View source
@classmethod
from_dates(
dates: _TimeCoordinateValues
) -> 'TimeCoordinates'
Creates a TimeCoordinates from a polymorphic series of dates.
| Args |
dates
|
A polymorphic series of dates; it can either be a Pandas
DatetimeIndex or an Xarray DataArray with "YYYY-mm-dd" string
labels.
|
| Returns |
A normalized TimeCoordinates dataclass.
|
get_selected_dates
View source
get_selected_dates(
selected_interval: (meridian.data.time_coordinates.DateInterval | None) = None
) -> list[datetime.date]
Creates a sequence of dates containing all points in selected interval.
| Args |
selected_interval
|
Tuple of the start and end times, or a DateInterval
proto. If None, then all_dates is returned.
|
| Returns |
A sequence of dates representing the subset of all_dates between the
given start and end dates, as Python's builtin datetime.date objects.
|
| Raises |
ValueError
|
If selected_interval is not a subset of all_dates.
|
__eq__
__eq__(
other
)
Return self==value.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-23 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-23 UTC."],[],[]]