mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-08-13 13:40:34 +00:00
fix(infra): write_jsonl mkdir+sort_keys, q16_div raise on zero
- write_jsonl: add path.parent.mkdir(parents=True, exist_ok=True) to prevent FileNotFoundError when output dir doesn't exist - write_jsonl: add sort_keys=True to match original callers' deterministic output behavior (AGENTS.md: identical SHA256 on consecutive runs) - q16_div: raise ZeroDivisionError instead of silently returning 0, matching the original fractal_dimension.py semantics Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
This commit is contained in:
parent
a496d8d3ce
commit
f6f9122d24
2 changed files with 4 additions and 3 deletions
|
|
@ -23,11 +23,12 @@ def load_jsonl(path: Path) -> list[dict[str, Any]]:
|
|||
|
||||
|
||||
def write_jsonl(path: Path, rows: list[dict[str, Any]], *, append: bool = False) -> None:
|
||||
"""Write a list of dicts as JSONL."""
|
||||
"""Write a list of dicts as JSONL (sorted keys for deterministic output)."""
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
mode = "a" if append else "w"
|
||||
with path.open(mode, encoding="utf-8") as fh:
|
||||
for row in rows:
|
||||
fh.write(json.dumps(row, ensure_ascii=False) + "\n")
|
||||
fh.write(json.dumps(row, sort_keys=True, ensure_ascii=False) + "\n")
|
||||
|
||||
|
||||
def stable_json(obj: Any) -> str:
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ def q16_mul(a: int, b: int) -> int:
|
|||
def q16_div(a: int, b: int) -> int:
|
||||
"""Divide two Q16_16 values with normalization."""
|
||||
if b == 0:
|
||||
return 0
|
||||
raise ZeroDivisionError("Q16 division by zero")
|
||||
return (a * Q16_ONE) // b
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue