Refactor preprocessing logic for Chronos-2#493
Draft
shchur wants to merge 7 commits into
Draft
Conversation
shchur
commented
Apr 28, 2026
abdulfatir
reviewed
Apr 30, 2026
Contributor
abdulfatir
left a comment
There was a problem hiding this comment.
Thanks @shchur!
Overall, I don't have major concerns. The main thing we need to be fine with is that now there will be multiple validation paths which must be maintained. However, I think the major ones are list_of_dicts and dataframe, so it should not be too difficult to keep them tidy.
| ... | ||
|
|
||
|
|
||
| def from_dict_list( |
Contributor
There was a problem hiding this comment.
Maybe list_of_dicts to align with the naming elsewhere?
Comment on lines
+264
to
+265
| - Unseen (item, category) pairs get the item mean as fallback (via smoothing formula) | ||
| - Completely unseen categories in future (cat_code=-1) get the item mean |
Contributor
There was a problem hiding this comment.
What's the difference between these two?
| - future_id_codes (if provided) are valid item IDs that appear in id_codes | ||
| - future_cat_codes may contain -1 for unseen categories (encoded as NaN) | ||
|
|
||
| Edge cases |
Contributor
There was a problem hiding this comment.
What about NaNs in the categories (not in target)?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Converting raw data to
list[PreparedInput]is extremely slow when categorical covariates are present. For M5 (30K items, 50M rows, 7 categorical columns), preprocessing takes ~8 minutes. The bottlenecks are:validate_df_inputsandvalidate_and_prepare_single_dict_inputProposed design
New module
chronos/chronos2/preprocess.pywith four entry points:from_tensor()from_tensor_list()from_dataframe()from_dict_list()Key changes:
_target_encode()uses bincount across all items at once instead of per-item sklearn callsBreaking changes
list[dict]inputs (all items must have same structure)Expected speedup
~20x faster on M5 dataset (8 min → ~25s based on earlier prototyping)
This PR contains only the design (signatures + docstrings). Implementation to follow.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.