Skip to content

Update Darts models and make log and unlog inside stepshifter#43

Merged
xiaolong0728 merged 11 commits intodevelopmentfrom
cleanup
Nov 25, 2025
Merged

Update Darts models and make log and unlog inside stepshifter#43
xiaolong0728 merged 11 commits intodevelopmentfrom
cleanup

Conversation

@xiaolong0728
Copy link
Collaborator

  1. Darts now support classification models. Remove previous self-created models and import from darts
  2. Log and unlog data inside views-stepshifter. No transformed data in and out

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the Darts model usage and internalizes data transformations within the stepshifter. The main changes upgrade to Darts 0.38.0 which now includes native classification model support, eliminating the need for custom implementations. Additionally, log/expm1 transformations are now performed internally rather than requiring pre-transformed data inputs.

  • Upgraded Darts dependency from ^0.30.0 to ^0.38.0 to leverage built-in classification models
  • Moved log1p/expm1 transformations inside StepshifterModel's data processing and prediction methods
  • Simplified darts_model.py by removing extensive custom model implementations and using thin wrappers instead

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
views_stepshifter/models/stepshifter.py Added log1p transformation in _process_data and expm1 in _predict_by_step; updated deprecated pd_dataframe() to to_dataframe(); removed unused ModelManager import and commented out CUDA code
views_stepshifter/models/hurdle_model.py Replaced custom classification models with native Darts imports (XGBClassifierModel, LightGBMClassifierModel) and removed RandomForestClassifier support
views_stepshifter/models/darts_model.py Drastically reduced file from 1221 to 30 lines by replacing custom model implementations with simple wrapper classes that inherit from Darts models
views_stepshifter/models/init.py Removed exports for deleted custom model classes (XGBClassifierModel, LightGBMClassifierModel, RandomForestClassifierModel)
views_stepshifter/manager/stepshifter_manager.py Fixed typo: changed all references from 'config' to 'configs' to match the actual attribute name
tests/test_stepshifter_manager.py Enhanced test setup with proper mocking, added validation patching, and corrected attribute references from 'config' to 'configs'
tests/test_hurdle_model.py Updated sample config to use LGBM models instead of RandomForest models that were removed
pyproject.toml Upgraded darts dependency from ^0.30.0 to ^0.38.0

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

else:
self.config["model_reg"] = self.config["algorithm"]
model = StepshifterModel(self.config, partitioner_dict)
self.configs = {"model_reg": self.configs["algorithm"]}
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

This line overwrites the entire configs dictionary with a single key-value pair, discarding all other configuration. It should update the dictionary instead: self.configs['model_reg'] = self.configs['algorithm']

Suggested change
self.configs = {"model_reg": self.configs["algorithm"]}
self.configs["model_reg"] = self.configs["algorithm"]

Copilot uses AI. Check for mistakes.
path_artifact = self._model_path.get_latest_model_artifact_path(run_type)

self.config["timestamp"] = path_artifact.stem[-15:]
self.configs = {"timestamp": path_artifact.stem[-15:]}
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

This line overwrites the entire configs dictionary with only the timestamp, losing all other configuration values. It should update the dictionary instead: self.configs['timestamp'] = path_artifact.stem[-15:]

Copilot uses AI. Check for mistakes.
path_artifact = self._model_path.get_latest_model_artifact_path(run_type)

self.config["timestamp"] = path_artifact.stem[-15:]
self.configs = {"timestamp": path_artifact.stem[-15:]}
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

This line overwrites the entire configs dictionary with only the timestamp, losing all other configuration values. It should update the dictionary instead: self.configs['timestamp'] = path_artifact.stem[-15:]

Suggested change
self.configs = {"timestamp": path_artifact.stem[-15:]}
self.configs["timestamp"] = path_artifact.stem[-15:]

Copilot uses AI. Check for mistakes.
stepshifter_manager_hurdle.configs = hurdle_args

stepshifter_manager_hurdle._get_model(mock_partitioner_dict)
mock_hurdle_model.assert_called_once_with(stepshifter_manager_hurdle.config, mock_partitioner_dict)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The assertion references stepshifter_manager_hurdle.config, but the attribute has been renamed to configs throughout the codebase. This should be stepshifter_manager_hurdle.configs.

Copilot uses AI. Check for mistakes.
stepshifter_manager.configs = non_hurdle_args

stepshifter_manager._get_model(mock_partitioner_dict)
mock_stepshifter_model.assert_called_once_with(stepshifter_manager.config, mock_partitioner_dict)
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The assertion references stepshifter_manager.config, but the attribute has been renamed to configs throughout the codebase. This should be stepshifter_manager.configs.

Suggested change
mock_stepshifter_model.assert_called_once_with(stepshifter_manager.config, mock_partitioner_dict)
mock_stepshifter_model.assert_called_once_with(stepshifter_manager.configs, mock_partitioner_dict)

Copilot uses AI. Check for mistakes.
artifact_name = None
stepshifter_manager._evaluate_model_artifact(eval_type, artifact_name)

assert stepshifter_manager.config["run_type"] == "test_run_type"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The assertion references stepshifter_manager.config, but the attribute has been renamed to configs. This should be stepshifter_manager.configs['run_type'].

Suggested change
assert stepshifter_manager.config["run_type"] == "test_run_type"
assert stepshifter_manager.configs["run_type"] == "test_run_type"

Copilot uses AI. Check for mistakes.

assert stepshifter_manager.config["run_type"] == "test_run_type"
mock_logger.info.assert_called_once_with(f"Using latest (default) run type (test_run_type) specific artifact")
assert stepshifter_manager.config["timestamp"] == "202401011200000"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The assertion references stepshifter_manager.config, but the attribute has been renamed to configs. This should be stepshifter_manager.configs['timestamp'].

Suggested change
assert stepshifter_manager.config["timestamp"] == "202401011200000"
assert stepshifter_manager.configs["timestamp"] == "202401011200000"

Copilot uses AI. Check for mistakes.
assert stepshifter_manager.config["timestamp"] == "202401011200000"
# mock_read_dataframe.assert_called_once()
mock_model.predict.assert_called_once_with("test_run_type")
assert stepshifter_manager.config["run_type"] == "forecasting"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The assertion references stepshifter_manager.config, but the attribute has been renamed to configs. This should be stepshifter_manager.configs['run_type'].

Copilot uses AI. Check for mistakes.
eval_type = "test_eval_type"
stepshifter_manager._evaluate_sweep(eval_type, mock_model)

assert stepshifter_manager.config["run_type"] == "test_run_type"
Copy link

Copilot AI Nov 24, 2025

Choose a reason for hiding this comment

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

The assertion references stepshifter_manager.config, but the attribute has been renamed to configs. This should be stepshifter_manager.configs['run_type'].

Suggested change
assert stepshifter_manager.config["run_type"] == "test_run_type"
assert stepshifter_manager.configs["run_type"] == "test_run_type"

Copilot uses AI. Check for mistakes.
@xiaolong0728 xiaolong0728 merged commit 3cb52c6 into development Nov 25, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant