Skip to content

Commit f5940e3

Browse files
committed
refactor: clean up code formatting and improve readability in demo and backend tests
1 parent 6251425 commit f5940e3

3 files changed

Lines changed: 9 additions & 11 deletions

File tree

sandbox/khisto_demo.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@
453453
},
454454
{
455455
"cell_type": "code",
456-
"execution_count": 13,
456+
"execution_count": null,
457457
"id": "1190f8aa",
458458
"metadata": {},
459459
"outputs": [
@@ -484,12 +484,12 @@
484484
"print(\"\\nGranularity levels:\")\n",
485485
"for r in results:\n",
486486
" marker = \" ← BEST\" if r.is_best else \"\"\n",
487-
" print(f\" Granularity {r.granularity}: {len(r.frequency)} bins{marker}\")"
487+
" print(f\" Granularity {r.granularity}: {len(r.frequencies)} bins{marker}\")"
488488
]
489489
},
490490
{
491491
"cell_type": "code",
492-
"execution_count": 14,
492+
"execution_count": null,
493493
"id": "bf2ba150",
494494
"metadata": {},
495495
"outputs": [
@@ -512,8 +512,8 @@
512512
"\n",
513513
"for i, r in enumerate(results[:n_levels]):\n",
514514
" ax = axes[i]\n",
515-
" ax.stairs(r.frequency, r.bin_edges, fill=True, alpha=0.7)\n",
516-
" title = f\"Granularity {r.granularity} ({len(r.frequency)} bins)\"\n",
515+
" ax.stairs(r.frequencies, r.bin_edges, fill=True, alpha=0.7)\n",
516+
" title = f\"Granularity {r.granularity} ({len(r.frequencies)} bins)\"\n",
517517
" if r.is_best:\n",
518518
" title += \" ★ BEST\"\n",
519519
" ax.set_facecolor(\"#ffffee\")\n",

src/khisto/core/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ def _format_runtime_error(
170170

171171

172172
def _process_histogram_file(
173-
temp_output_file_path: str,
173+
file_path: str,
174174
) -> list[HistogramResult]:
175175
"""Process exploratory JSON generated by khisto CLI."""
176-
with open(temp_output_file_path, "r") as temp_output_file:
176+
with open(file_path, "r") as temp_output_file:
177177
khisto_output: _KhistoOutput = _KhistoOutput.from_dict(
178178
json.load(temp_output_file)
179179
)

tests/core/test_backend.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,7 @@ def test_series_selects_finest_interpretable_histogram(self, tmp_path):
240240
}
241241
self._write_json(tmp_path / "histogram.series.json", payload)
242242

243-
with (tmp_path / "histogram.series.json").open("r", encoding="utf-8") as stream:
244-
results = _process_histogram_file(stream)
243+
results = _process_histogram_file(str(tmp_path / "histogram.series.json"))
245244

246245
assert len(results) == 3
247246
assert [result.granularity for result in results] == [0, 2, 3]
@@ -278,8 +277,7 @@ def test_series_keeps_finest_histogram_when_all_interpretable(self, tmp_path):
278277
}
279278
self._write_json(tmp_path / "histogram.series.json", payload)
280279

281-
with (tmp_path / "histogram.series.json").open("r", encoding="utf-8") as stream:
282-
results = _process_histogram_file(stream)
280+
results = _process_histogram_file(str(tmp_path / "histogram.series.json"))
283281

284282
assert len(results) == 2
285283
assert [result.is_best for result in results] == [False, True]

0 commit comments

Comments
 (0)