Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/operand error with encoders #2034

Merged
merged 4 commits into from
Oct 28, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions darts/utils/data/tabularization.py
madtoinou marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -884,11 +884,25 @@ def _create_lagged_data_by_moving_window(
# If `start_time` not included in `time_index_i`, can 'manually' calculate
# what its index *would* be if `time_index_i` were extended to include that time:
if not is_target_series and (time_index_i[-1] <= start_time):
start_time_idx = (
len(time_index_i)
- 1
+ (start_time - time_index_i[-1]) // series_i.freq
)
# Series frequency represents a non-ambiguous timedelta value (not ‘M’, ‘Y’ or ‘y’)
if pd.to_timedelta(series_i.freq, errors="coerce") is not pd.NaT:
start_time_idx = (
len(time_index_i)
- 1
+ (start_time - time_index_i[-1]) // series_i.freq
)
else:
# Create a temporary DatetimeIndex to extract the actual start index.
start_time_idx = (
len(
pd.date_range(
start=time_index_i[0],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be more efficient to generate the index from the end of the series instead of from the beginning and then just add the len(time_index_i) to it?

Also we could use our darts.utils.timeseries_generation.generate_index for that

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I don't know if this is much faster but at least, it looks similar to the other case

end=start_time,
freq=series_i.freq,
)
)
- 1
)
elif not is_target_series and (time_index_i[0] >= start_time):
start_time_idx = max_lag_i
# If `start_time` *is* included in `time_index_i`, need to binary search `time_index_i`
Expand Down