#!/usr/bin/env python3 # -*- coding: utf-8 -*- """probe_constituent.py — 单元3 前置: 探查成份股两源 schema (写 migrate 前必须看清)。 1. bs_index_constituent (DB, baostock 300/500/50 历史): cols/rows/distinct index_code/抽样 2. data/index_const_hist/*.parquet (akshare cni 深证 union): 文件列表 + 每个 shape/cols/抽样 """ import glob import os import sqlite3 import pandas as pd DB = r"C:\sanguo_vnpy_v2\data\quant_trading.db" HIST = r"C:\sanguo_vnpy_v2\data\index_const_hist" c = sqlite3.connect(DB, timeout=60) c.execute("PRAGMA busy_timeout = 60000") cols = [r[1] for r in c.execute("PRAGMA table_info(bs_index_constituent)")] print("[bs_index_constituent] cols:", cols) print(" rows:", c.execute("SELECT COUNT(*) FROM bs_index_constituent").fetchone()[0]) idx = [r[0] for r in c.execute( "SELECT DISTINCT index_code FROM bs_index_constituent ORDER BY index_code")] print(" distinct index_code:", idx) print(" distinct updateDate count:", c.execute( "SELECT COUNT(DISTINCT updateDate) FROM bs_index_constituent").fetchone()[0]) print(" sample rows:", c.execute( "SELECT * FROM bs_index_constituent LIMIT 3").fetchall()) c.close() print("\n[index_const_hist parquets]") files = sorted(glob.glob(os.path.join(HIST, "*.parquet"))) print("files:", [os.path.basename(f) for f in files]) for f in files: df = pd.read_parquet(f) print(f" {os.path.basename(f)}: shape={df.shape} cols={list(df.columns)}") print(f" head:\n{df.head(2).to_string()}")