fix(data): provide _dataset_uri fallback on DatasetProvider#2214
Open
genisis0x wants to merge 1 commit into
Open
fix(data): provide _dataset_uri fallback on DatasetProvider#2214genisis0x wants to merge 1 commit into
genisis0x wants to merge 1 commit into
Conversation
Fixes microsoft#1843. When qlib runs without a `DatasetCache` wrapper the `DatasetD` `Wrapper` registers a bare `LocalDatasetProvider` instance. `LocalProvider.features_uri` then calls `DatasetD._dataset_uri(...)` unconditionally, which goes through `Wrapper.__getattr__` to look up `_dataset_uri` on the provider — and `LocalDatasetProvider` doesn't have one. The cache-aware override lives on `DatasetCache` / `DiskDatasetCache` only, so the no-cache code path crashes with `AttributeError: 'LocalDatasetProvider' object has no attribute '_dataset_uri'`. Add a base `_dataset_uri` to `DatasetProvider` that returns `""` by convention — the same "no URI, fetch directly" signal that `DiskDatasetCache._dataset_uri` already emits on its `disk_cache == 0` branch. Cache subclasses continue to override this with a real URI implementation, so the wrapped-with-cache path is unchanged. The new fallback covers any provider that subclasses `DatasetProvider` without going through a cache (LocalDatasetProvider, ClientDatasetProvider, plus any third-party providers users register). Adds `tests/misc/test_dataset_provider_uri.py` with three regressions: attribute presence, the empty-string return, and stability across `disk_cache` values so future refactors can't reintroduce the crash.
Author
|
Read through the CLA — all good. @microsoft-github-policy-service agree |
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.
Summary
Fixes #1843. When qlib runs without a `DatasetCache` wrapper, the global `DatasetD` `Wrapper` is registered with a bare `LocalDatasetProvider` instance. `LocalProvider.features_uri` (`qlib/data/data.py:1221`) then calls:
```python
return DatasetD._dataset_uri(instruments, fields, start_time, end_time, freq, disk_cache)
```
That goes through `Wrapper.getattr` to find `_dataset_uri` on the provider — and `LocalDatasetProvider` doesn't have one. The cache-aware override lives on `DatasetCache` / `DiskDatasetCache` only, so the no-cache code path crashes with:
```
AttributeError: 'LocalDatasetProvider' object has no attribute '_dataset_uri'
```
Approach
Add a base `_dataset_uri` to `DatasetProvider` that returns `""` by convention. That mirrors the existing `""` = "no URI, fetch directly" signal that `DiskDatasetCache._dataset_uri` already emits on its `disk_cache == 0` branch (`qlib/data/cache.py:750`), so the contract isn't a new invention — the caller already handles `""` correctly.
Cache subclasses keep their explicit overrides, so the wrapped-with-cache path is unchanged. The fallback also covers `ClientDatasetProvider` and any third-party providers that subclass `DatasetProvider` without routing through a cache, not just `LocalDatasetProvider` specifically.
Test
New `tests/misc/test_dataset_provider_uri.py` with three regressions:
```
$ .venv/bin/python -m pytest tests/misc/test_dataset_provider_uri.py -v
tests/misc/test_dataset_provider_uri.py::DatasetProviderURITest::test_disk_cache_value_is_ignored_in_fallback PASSED
tests/misc/test_dataset_provider_uri.py::DatasetProviderURITest::test_local_dataset_provider_has_dataset_uri PASSED
tests/misc/test_dataset_provider_uri.py::DatasetProviderURITest::test_local_dataset_provider_returns_empty_uri PASSED
============================== 3 passed in 0.94s ===============================
```
Fixes #1843