(sorted_df: pl.DataFrame, rows_removed_by_deduplication: int)
| 113 | |
| 114 | |
| 115 | def _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 | |
| 157 | def _interval_to_seconds(interval: str) -> int: |
no test coverage detected