unsafe_sorted_range_slice_idxs#

openstef_core.utils.pandas.unsafe_sorted_range_slice_idxs(data: Series | Index, start: datetime | Timestamp | None, end: datetime | Timestamp | None) → tuple[int, int][source]#

Get sorted slice indices for a datetime range.

Efficiently finds the start and end indices for slicing a sorted datetime series within a specified time range. Uses binary search for optimal performance on large datasets.

This function is particularly useful when working with large time series datasets where you need to quickly extract data for specific time windows without iterating through all data points.

Parameters:
  • data (Series | Index) – Sorted pandas Series with datetime index or values to search.

  • start (datetime | Timestamp | None) – Start of the time range (inclusive). If None, starts from beginning.

  • end (datetime | Timestamp | None) – End of the time range (exclusive). If None, goes to the end.

Returns:

Tuple of (start_index, end_index) for slicing the data series.

Return type:

tuple[int, int]

Note

This function assumes that the input series is sorted in ascending order. It does not perform any checks to verify this, so it’s up to the caller to ensure that this invariant holds true.

Parameters:
Return type:

tuple[int, int]