Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.

Commit 7578ef2

Browse files
committed
Remove dead code and associated test.
1 parent afd5e83 commit 7578ef2

File tree

2 files changed

+0
-70
lines changed

2 files changed

+0
-70
lines changed

bigquery_magics/bigquery.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -634,44 +634,6 @@ def _colab_node_expansion_callback(request: dict, params_str: str):
634634
MAX_GRAPH_VISUALIZATION_QUERY_RESULT_SIZE = 100_000
635635

636636

637-
def _estimate_json_size(df: pandas.DataFrame) -> int:
638-
"""Approximates the length of df.to_json(orient='records')
639-
without materializing the string.
640-
"""
641-
num_rows, num_cols = df.shape
642-
if num_rows == 0:
643-
return 2 # "[]"
644-
645-
# 1. Key overhead: "column_name": (repeated for every row)
646-
# Includes quotes, colon, and comma separator per field
647-
key_overhead = sum(len(f'"{col}":') + 1 for col in df.columns) * num_rows
648-
649-
# 2. Row structural overhead: { } per row and [ ] for the list
650-
# Plus commas between rows (num_rows - 1)
651-
structural_overhead = (2 * num_rows) + 2 + (num_rows - 1)
652-
653-
# 3. Value lengths
654-
total_val_len = 0
655-
for col in df.columns:
656-
series = df[col]
657-
658-
if pandas.api.types.is_bool_dtype(series):
659-
# true (4) or false (5)
660-
total_val_len += series.map({True: 4, False: 5}).sum()
661-
elif pandas.api.types.is_numeric_dtype(series):
662-
# Numeric values (no quotes). Sample for average length to save memory.
663-
sample_size = min(len(series), 1000)
664-
avg_len = series.sample(sample_size).astype(str).str.len().mean()
665-
total_val_len += avg_len * num_rows
666-
else:
667-
# Strings/Objects: "value" + quotes (2) + rough escaping factor
668-
# .str.len() is relatively memory-efficient
669-
val_chars = series.astype(str).str.len().sum()
670-
total_val_len += val_chars + (2 * num_rows)
671-
672-
return int(key_overhead + structural_overhead + total_val_len)
673-
674-
675637
def _get_graph_name(query_text: str):
676638
"""Returns the name of the graph queried.
677639

tests/unit/bigquery/test_bigquery.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3186,35 +3186,3 @@ def test_test_bigquery_magic__extension_loaded__is_registered_set_to_true():
31863186
ip.extension_manager.load_extension("bigquery_magics")
31873187

31883188
assert bigquery_magics.is_registered is True
3189-
3190-
3191-
def test__estimate_json_size_empty():
3192-
df = pandas.DataFrame()
3193-
assert magics._estimate_json_size(df) == 2
3194-
3195-
3196-
def test__estimate_json_size_bool():
3197-
df = pandas.DataFrame({"a": [True, False]}, dtype="bool")
3198-
# key_overhead: (len('"a":') + 1) * 2 = 5 * 2 = 10
3199-
# structural_overhead: (2 * 2) + 2 + (2 - 1) = 7
3200-
# total_val_len: 4 (true) + 5 (false) = 9
3201-
# total = 10 + 7 + 9 = 26
3202-
assert magics._estimate_json_size(df) == 26
3203-
3204-
3205-
def test__estimate_json_size_int():
3206-
df = pandas.DataFrame({"a": [3, 4]})
3207-
# key_overhead: (len('"a":') + 1) * 2 = 5 * 2 = 10
3208-
# structural_overhead: (2 * 2) + 2 + (2 - 1) = 7
3209-
# total_val_len: 4 (true) + 5 (false) = 9
3210-
# total = 10 + 7 + 9 = 26
3211-
assert magics._estimate_json_size(df) == 19
3212-
3213-
3214-
def test__estimate_json_size_string():
3215-
df = pandas.DataFrame({"a": ["x", "yz"]})
3216-
# key_overhead: (len('"a":') + 1) * 2 = 5 * 2 = 10
3217-
# structural_overhead: (2 * 2) + 2 + (2 - 1) = 7
3218-
# total_val_len: (1 + 2) + (2 * 2) = 7
3219-
# total = 10 + 7 + 7 = 24
3220-
assert magics._estimate_json_size(df) == 24

0 commit comments

Comments
 (0)