|
7 | 7 | import uuid |
8 | 8 | import logging |
9 | 9 | import textwrap |
| 10 | +from humanize import metric, naturalsize |
10 | 11 | from itertools import zip_longest |
11 | 12 | from pathlib import Path |
12 | 13 | from hyperscript import h |
@@ -4186,15 +4187,14 @@ def _create_evaluation_model_annotation( |
4186 | 4187 | execution_stats_str = "" |
4187 | 4188 | if execution_stats: |
4188 | 4189 | rows_processed = execution_stats.total_rows_processed |
4189 | | - execution_stats_str += ( |
4190 | | - f"{_abbreviate_integer_count(rows_processed)} row{'s' if rows_processed > 1 else ''}" |
4191 | | - if rows_processed |
4192 | | - else "" |
4193 | | - ) |
| 4190 | + if rows_processed: |
| 4191 | + # 1.00 and 1.0 to 1 |
| 4192 | + rows_processed_str = metric(rows_processed).replace(".00", "").replace(".0", "") |
| 4193 | + execution_stats_str += f"{rows_processed_str} row{'s' if rows_processed > 1 else ''}" |
4194 | 4194 |
|
4195 | 4195 | bytes_processed = execution_stats.total_bytes_processed |
4196 | 4196 | execution_stats_str += ( |
4197 | | - f"{', ' if execution_stats_str else ''}{_format_bytes(bytes_processed)}" |
| 4197 | + f"{', ' if execution_stats_str else ''}{naturalsize(bytes_processed, binary=True)}" |
4198 | 4198 | if bytes_processed |
4199 | 4199 | else "" |
4200 | 4200 | ) |
@@ -4299,39 +4299,3 @@ def _calculate_annotation_str_len( |
4299 | 4299 | + execution_stats_len, |
4300 | 4300 | ) |
4301 | 4301 | return annotation_str_len |
4302 | | - |
4303 | | - |
4304 | | -# Convert number of bytes to a human-readable string |
4305 | | -# https://github.com/dbt-labs/dbt-adapters/blob/34fd178539dcb6f82e18e738adc03de7784c032f/dbt-bigquery/src/dbt/adapters/bigquery/connections.py#L165 |
4306 | | -def _format_bytes(num_bytes: t.Optional[int]) -> str: |
4307 | | - if num_bytes and num_bytes >= 0: |
4308 | | - if num_bytes < 1024: |
4309 | | - return f"{num_bytes} bytes" |
4310 | | - |
4311 | | - num_bytes_float = float(num_bytes) / 1024.0 |
4312 | | - for unit in ["KiB", "MiB", "GiB", "TiB", "PiB"]: |
4313 | | - if num_bytes_float < 1024.0: |
4314 | | - return f"{num_bytes_float:3.1f} {unit}" |
4315 | | - num_bytes_float /= 1024.0 |
4316 | | - |
4317 | | - num_bytes_float *= 1024.0 # undo last division in loop |
4318 | | - return f"{num_bytes_float:3.1f} {unit}" |
4319 | | - return "" |
4320 | | - |
4321 | | - |
4322 | | -# Abbreviate integer count. Example: 1,000,000,000 -> 1b |
4323 | | -# https://github.com/dbt-labs/dbt-adapters/blob/34fd178539dcb6f82e18e738adc03de7784c032f/dbt-bigquery/src/dbt/adapters/bigquery/connections.py#L178 |
4324 | | -def _abbreviate_integer_count(count: t.Optional[int]) -> str: |
4325 | | - if count and count >= 0: |
4326 | | - if count < 1000: |
4327 | | - return str(count) |
4328 | | - |
4329 | | - count_float = float(count) / 1000.0 |
4330 | | - for unit in ["k", "m", "b", "t"]: |
4331 | | - if count_float < 1000.0: |
4332 | | - return f"{count_float:3.1f}{unit}".strip() |
4333 | | - count_float /= 1000.0 |
4334 | | - |
4335 | | - count_float *= 1000.0 # undo last division in loop |
4336 | | - return f"{count_float:3.1f}{unit}".strip() |
4337 | | - return "" |
0 commit comments