refactor(cache): split TushareCache endpoint specs and parsers (D2) - #43
Merged
StackOverFlow11 merged 1 commit intoJun 19, 2026
Merged
Conversation
Behavior-preserving internal refactor of data/cache/tushare_cache.py — no cache semantics change. The 814-line facade is split so endpoint metadata and raw parsers are reviewable in small files: - data/cache/tushare_specs.py (new): endpoint identifiers, ALL_ENDPOINTS, _GLOBAL_KEY, canonical-raw column sets + natural keys, FINA_FIELDS, _INDEX_WINDOW_DAYS, raw->canonical rename maps. - data/cache/tushare_parsers.py (new): the 10 raw endpoint parsers (_parse_daily/_adj/_suspend/_stk_limit/_index_weight/_namechange/_stock_basic/ _daily_basic/_fina/_index_member), moved verbatim. - data/cache/tushare_planning.py (new): the two leaf helpers _fields_hash / _compact. - data/cache/tushare_cache.py: keeps the public TushareCache facade + the read-through engine (gap planning, 90-day index_weight paging, snapshot staleness, refresh_recent_days / recent_tail_overrides / not_ready_days / force_refresh, ok/empty/not_ready/failed coverage, one-row-per-natural-key upsert, stats / update_summary) and FetchOne/FetchSnapshot. 814 -> 596 lines. Backward-compatible imports preserved: the facade re-exports the endpoint ids + FINA_FIELDS + ALL_ENDPOINTS, so `from data.cache.tushare_cache import DAILY_BASIC, FINA_FIELDS, INDEX_WEIGHT, ...` (used by data/feed/tushare_fina.py and the cache tests) keep working unchanged. Public method signatures, internal planning, and every coverage semantic are unchanged; the existing cache tests are the behavior lock. Adds a narrow modularization regression test (re-export identity + parser module boundary). Non-goals (D3+): no schema registry, no data-quality validator, no concurrency, no CoverageLedger storage change, no PanelStore append/partition, no intraday cache refactor, no rate-limit/retry change, no factor/alpha/portfolio/runtime/ report change.
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
Data Layer D2 — behavior-preserving internal refactor of
data/cache/tushare_cache.py. The 814-line facade is split so endpoint metadataand raw parsers are reviewable in small files, while
TushareCachestays thepublic facade and every cache behavior is unchanged. This is not a cache
semantics change, not a performance/concurrency change, and not a data-quality
layer.
Changed files (6)
data/cache/tushare_specs.py(89 lines) — endpoint identifiers,ALL_ENDPOINTS,_GLOBAL_KEY, canonical-raw column sets + natural keys,FINA_FIELDS,_INDEX_WINDOW_DAYS, raw→canonical rename maps. Pure constants.data/cache/tushare_parsers.py(216 lines) — the 10 raw endpointparsers (
_parse_daily/_adj/_suspend/_stk_limit/_index_weight/_namechange/ _stock_basic/_daily_basic/_fina/_index_member), moved verbatim.data/cache/tushare_planning.py(22 lines) — the two leaf helpers_fields_hash/_compact.data/cache/tushare_cache.py— 814 → 596 lines; keeps the publicTushareCachefacade + read-through engine +FetchOne/FetchSnapshot;imports the moved pieces and re-exports the public names.
docs/data/data_layer_contracts.md— factually records D2 implemented(D3–D6 still not).
tests/test_tushare_cache_modularization.py(5 tests) — narrowre-export-identity + module-boundary regression guard.
What moved vs what stayed in
TushareCachehelpers.
daily_bars,adj_factor,suspend_d,stk_limit,daily_basic,fina_indicator,index_member_all,index_weight,namechange,stock_basic,stats,update_summary); dense per-symbol gap planning;index_weight90-day paging;snapshot/dimension staleness;
refresh_recent_days/recent_tail_overrides/not_ready_days/force_refresh;fetch_counts/written_counts/not_ready_counts; ok/empty/not_ready/failed coverage semantics; one-row-per-natural-key upsert.
Backward-compatible import guarantees
from data.cache.tushare_cache import TushareCacheand the constant imports(
DAILY_BASIC,FINA_INDICATOR,INDEX_MEMBER_ALL,INDEX_WEIGHT,NAMECHANGE,STK_LIMIT,STOCK_BASIC,SUSPEND_D,FINA_FIELDS,ALL_ENDPOINTS) all keepworking — the facade re-exports them (verified identity in the new test; exercised
by
data/feed/tushare_fina.pyand the existing cache tests).Verification
pytest tests/test_tushare_cache_market.py tests/test_tushare_cache_universe.py tests/test_tushare_cache_p4_3.py tests/test_data_updater.py tests/test_cache_config.py→ all pass.pytest -p no:cacheprovider→ 584 passed (579 prior + 5 new D2 tests).ruff check .→ All checks passed!validate-configover all 17config/*.yaml→ all OK.run-phase0 --config config/example.yaml→ic_mean=0.9600, annual_return=0.8408(no behavior drift).git diff --check main...HEAD→ clean; merge-marker scan → 0..config.jsontoken value 0 hits; no FAKE token in changed files.Behavior-preserving internal refactor — no cache semantics change. Please
review before merge.