fix: DDG-DA workflow - LightGBM 4.0+ compatibility and pandas issues#2234
Open
Olcmyk wants to merge 4 commits into
Open
fix: DDG-DA workflow - LightGBM 4.0+ compatibility and pandas issues#2234Olcmyk wants to merge 4 commits into
Olcmyk wants to merge 4 commits into
Conversation
…aset chain The RestrictedUnpickler safelist introduced by the recent security hardening (microsoft#2099 / microsoft#2076 / microsoft#2153) only covered the abstract ``DataHandler`` / ``DataHandlerLP`` classes plus ``StaticDataLoader``. Any rolling workflow that pickles a real Dataset (the default for ``Rolling._train_rolling_tasks``) walks into one of the contrib stock handlers and now crashes on reload (issue microsoft#2130): UnpicklingError: Forbidden class: qlib.contrib.data.handler.Alpha158. Only whitelisted classes are allowed for security reasons. ... Unrolling workflows happened to use a path that did not go through the restricted loader, which is why downgrading to 0.9.7 hid the issue. Extend ``SAFE_PICKLE_CLASSES`` with the qlib-internal classes that sit on the standard recorder pickle graph: * The four shipped contrib handlers: ``Alpha158``, ``Alpha158vwap``, ``Alpha360``, ``Alpha360vwap``. * The dataset wrappers (``Dataset``, ``DatasetH``, ``TSDatasetH``) and the additional concrete loaders (``DataLoader``, ``DLWParser``, ``QlibDataLoader``, ``NestedDataLoader``, ``DataLoaderDH``). * Every concrete ``Processor`` defined in ``qlib.data.dataset.processor`` -- they show up in every realistic ``learn_processors`` / ``infer_processors`` chain. These are all classes already shipped inside qlib itself, so adding them does not weaken the threat model the safelist was designed against (arbitrary code execution through external pickle payloads). Add regression tests pinning each added entry plus an end-to-end check that ``RestrictedUnpickler.find_class`` actually resolves ``Alpha158`` and that other unknown classes are still rejected. Fixes microsoft#2130
PR microsoft#2213 added Alpha158/Alpha360 handlers to the pickle whitelist but missed qlib.utils.data.zscore, which is also required by the DDG-DA workflow. Without this, DDG-DA fails with: UnpicklingError: Forbidden class: qlib.utils.data.zscore This commit adds zscore to the whitelist and includes a test to prevent regression. Fixes microsoft#2130 (supplement to PR microsoft#2213)
DDG-DA workflow pickles and reloads InternalData objects during meta-learning
data selection. Without this whitelist entry, the workflow fails with:
UnpicklingError: Forbidden class: qlib.contrib.meta.data_selection.dataset.InternalData
Changes:
- Add InternalData to SAFE_PICKLE_CLASSES in qlib/utils/pickle_utils.py
- Add test case test_internal_data_is_safelisted to verify the whitelist entry
This is part of the fix for issue microsoft#2130 - DDG-DA workflow requires multiple
classes to be whitelisted for pickle deserialization.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit fixes three sequential bugs that prevented DDG-DA workflow from running.
Each bug masked the next one, making them impossible to discover without fixing
the previous bug first.
Bug 1: LightGBM 4.0+ Compatibility
- Problem: LightGBM 4.0+ no longer accepts None for early_stopping_rounds
- Fix: Only create early_stopping callback when rounds is not None
- Files: qlib/contrib/model/gbdt.py, qlib/contrib/model/highfreq_gdbt_model.py
Bug 2: Unhashable List Type Error
- Problem: data_key was a list [start_date, end_date], cannot be used as dict keys
- Fix: Convert list to tuple to make it hashable
- File: qlib/contrib/meta/data_selection/dataset.py (line 99-100)
Bug 3: Incorrect Pandas MultiIndex Selection
- Problem: Wrong syntax df.loc(axis=0) and group_keys=False caused index issues
- Fix: Use df.xs("label", level=1) for correct MultiIndex selection
- File: qlib/contrib/meta/data_selection/dataset.py (line 112-114)
Testing:
✅ DDG-DA workflow runs successfully end-to-end
✅ All 154 training tasks complete without errors
✅ Meta-learning data selection works correctly
✅ Final backtest results generated successfully
Dependencies:
- Requires PR microsoft#2230 (zscore and InternalData pickle whitelist) to be merged first
- Without PR microsoft#2230, workflow fails earlier with UnpicklingError
Fixes issue microsoft#2130 (DDG-DA workflow broken)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Description
This PR fixes the DDG-DA (Data Distribution Guided Domain Adaptation) workflow, which is completely broken due to a chain of three sequential bugs. Each bug masks the next one, making them impossible to discover without fixing the previous bug first.
The three bugs fixed in this PR:
LightGBM 4.0+ Compatibility Issue
Noneforearly_stopping_roundsparameterqlib/contrib/model/gbdt.pyandqlib/contrib/model/highfreq_gdbt_model.pyto only create early_stopping callback when the value is notNoneUnhashable List Type Error
data_keywas a list[start_date, end_date], which cannot be used as dictionary keys or DataFrame column namesqlib/contrib/meta/data_selection/dataset.pyto convert list to tuple (line 99-100)Incorrect Pandas MultiIndex Selection
df.loc(axis=0)[:, "pred"]andgroup_keys=Falsecaused loss of datetime indexqlib/contrib/meta/data_selection/dataset.pyto usedf.xs("label", level=1)for correct MultiIndex selection (line 112-114)Files changed:
qlib/contrib/model/gbdt.py- LightGBM 4.0+ compatibilityqlib/contrib/model/highfreq_gdbt_model.py- LightGBM 4.0+ compatibilityqlib/contrib/meta/data_selection/dataset.py- Unhashable list fix + pandas indexing fixMotivation and Context
Related Issues:
Why is this change required?
The DDG-DA workflow has been completely non-functional due to these bugs. The bugs form a dependency chain where each bug completely blocks execution, masking all subsequent bugs:
Root Causes:
Bug 1: LightGBM 4.0 introduced a breaking change where
lgb.early_stopping()no longer acceptsNone. The DDG-DA workflow explicitly setsearly_stopping_rounds=Noneto disable early stopping, causing:Bug 2: The code attempts to use a list as a dictionary key when creating a DataFrame:
Bug 3: Incorrect pandas syntax and
group_keys=Falsecaused index structure issues:How Has This Been Tested?
pytest qlib/tests/test_all_pipeline.pyunder upper directory ofqlib.Additional Testing:
Test Environment:
Test Command:
cd examples/benchmarks_dynamic/DDG-DA rm -rf mlruns python workflow.py runTest Results:
✅ All 154 meta-model training tasks completed successfully
✅ Data similarity matrix calculated correctly
✅ Meta-learning model trained with data selection
✅ Final predictions and backtest results generated
Screenshots of Test Results (if appropriate):
Pipeline test: ✅ Passed
Your own tests:
Before the fix:
After the fix:
DDG-DA workflow now runs successfully end-to-end! 🎉
Types of changes
Additional Notes
Why are these fixes combined in one PR?
These bugs form a true dependency chain, not an artificial grouping:
Backward Compatibility:
All fixes are backward compatible:
Dependencies:
Note: This PR's branch already includes PR #2230's changes. If PR #2230 is merged first, the commit history will be clean. If reviewing this PR independently, please note that commits
b5e58a00and0007720eare from PR #2230.Impact:
References: