Skip to content

Commit

Permalink
Intersect times indexes to avoid creating new TimeSeries for optimiza…
Browse files Browse the repository at this point in the history
…tion purposes.
  • Loading branch information
ymatzkevich committed Dec 13, 2024
1 parent e90107f commit 05a1667
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions darts/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2494,14 +2494,7 @@ def slice_intersect(self, other: Self) -> Self:
TimeSeries
a new series, containing the values of this series, over the time-span common to both time series.
"""
if other.has_same_time_as(self):
return self.__class__(self._xa)
if other.freq == self.freq:
start, end = self._slice_intersect_bounds(other)
return self[start:end]
else:
time_index = self.time_index.intersection(other.time_index)
return self[time_index]
return slice_intersect([self, other])[0]

def slice_intersect_values(self, other: Self, copy: bool = False) -> np.ndarray:
"""
Expand Down Expand Up @@ -5675,17 +5668,18 @@ def slice_intersect(series: Sequence[TimeSeries]) -> Sequence[TimeSeries]:
if not series:
return []

int_series = []
int_ts = series[0]
int_time_index = series[0].time_index
for ts in series[1:]:
int_ts = int_ts.slice_intersect(ts)
int_series.append(int_ts)
int_time_index = int_time_index.intersection(ts.time_index)

ts_other = series[0]
for ts in series[1:]:
ts = ts.slice_intersect(int_series[-1])
int_series.append(ts)
int_time_index = int_time_index.intersection(
ts.time_index.intersection(ts_other.time_index)
)
ts_other = ts

return int_series
return [ts[int_time_index] for ts in series]


def _finite_rows_boundaries(
Expand Down

0 comments on commit 05a1667

Please sign in to comment.