MCPcopy Create free account
hub / github.com/Open-Quant/openquant / _build_quality_report

Function _build_quality_report

python/openquant/data.py:115–154  ·  view source on GitHub ↗
(sorted_df: pl.DataFrame, rows_removed_by_deduplication: int)

Source from the content-addressed store, hash-verified

113
114
115def _build_quality_report(sorted_df: pl.DataFrame, rows_removed_by_deduplication: int) -> dict[str, Any]:
116 if sorted_df.height == 0:
117 return {
118 "row_count": 0,
119 "symbol_count": 0,
120 "duplicate_key_count": 0,
121 "gap_interval_count": 0,
122 "ts_min": None,
123 "ts_max": None,
124 "rows_removed_by_deduplication": rows_removed_by_deduplication,
125 "null_counts": dict(_ZERO_NULL_COUNTS),
126 }
127
128 summary = (
129 sorted_df.lazy()
130 .select(
131 pl.len().alias("row_count"),
132 pl.col("symbol").n_unique().alias("symbol_count"),
133 (
134 ((pl.col("symbol") == pl.col("symbol").shift(1)) & (pl.col("ts_us") == pl.col("ts_us").shift(1)))
135 .cast(pl.UInt32)
136 .sum()
137 ).alias("duplicate_key_count"),
138 _gap_expr(pl.col("symbol"), pl.col("ts_us")).cast(pl.UInt32).sum().alias("gap_interval_count"),
139 pl.col("ts").min().alias("ts_min"),
140 pl.col("ts").max().alias("ts_max"),
141 )
142 .collect()
143 .row(0, named=True)
144 )
145 return {
146 "row_count": int(summary["row_count"]),
147 "symbol_count": int(summary["symbol_count"]),
148 "duplicate_key_count": int(summary["duplicate_key_count"]),
149 "gap_interval_count": int(summary["gap_interval_count"]),
150 "ts_min": _format_ts(summary["ts_min"]),
151 "ts_max": _format_ts(summary["ts_max"]),
152 "rows_removed_by_deduplication": rows_removed_by_deduplication,
153 "null_counts": dict(_ZERO_NULL_COUNTS),
154 }
155
156
157def _interval_to_seconds(interval: str) -> int:

Callers 2

clean_ohlcvFunction · 0.85
data_quality_reportFunction · 0.85

Calls 3

_gap_exprFunction · 0.85
_format_tsFunction · 0.85
lenMethod · 0.80

Tested by

no test coverage detected