utils

Functions

determine_freq(timestamps)

Determine data frequency using provided timestamps.

determine_num_steps(start_timestamp, ...)

Determine how many steps of freq should we make from start_timestamp to reach end_timestamp.

select_observations(df, timestamps, freq[, ...])

Select observations from dataframe with known timeline.

determine_freq(timestamps: Union[pandas.core.series.Series, pandas.core.indexes.datetimes.DatetimeIndex]) str[source]

Determine data frequency using provided timestamps.

Parameters

timestamps (Union[pandas.core.series.Series, pandas.core.indexes.datetimes.DatetimeIndex]) – timeline to determine frequency

Returns

pandas frequency string

Raises

ValueError: – unable do determine frequency of data

Return type

str

determine_num_steps(start_timestamp: pandas._libs.tslibs.timestamps.Timestamp, end_timestamp: pandas._libs.tslibs.timestamps.Timestamp, freq: str) int[source]

Determine how many steps of freq should we make from start_timestamp to reach end_timestamp.

Parameters
  • start_timestamp (pandas._libs.tslibs.timestamps.Timestamp) – timestamp to start counting from

  • end_timestamp (pandas._libs.tslibs.timestamps.Timestamp) – timestamp to end counting, should be not earlier than start_timestamp

  • freq (str) – pandas frequency string: Offset aliases

Returns

number of steps

Raises
  • ValueError: – Value of end timestamp is less than start timestamp

  • ValueError: – Start timestamp isn’t correct according to a given frequency

  • ValueError: – End timestamp isn’t reachable with a given frequency

Return type

int

select_observations(df: pandas.core.frame.DataFrame, timestamps: pandas.core.series.Series, freq: str, start: Optional[Union[str, pandas._libs.tslibs.timestamps.Timestamp]] = None, end: Optional[Union[str, pandas._libs.tslibs.timestamps.Timestamp]] = None, periods: Optional[int] = None) pandas.core.frame.DataFrame[source]

Select observations from dataframe with known timeline.

Parameters
  • df (pandas.core.frame.DataFrame) – dataframe with known timeline

  • timestamps (pandas.core.series.Series) – series of timestamps to select

  • freq (str) – pandas frequency string

  • start (Optional[Union[str, pandas._libs.tslibs.timestamps.Timestamp]]) – start of the timeline

  • end (Optional[Union[str, pandas._libs.tslibs.timestamps.Timestamp]]) – end of the timeline

  • periods (Optional[int]) – number of periods in the timeline

Returns

dataframe with selected observations

Return type

pandas.core.frame.DataFrame