From 8aef0b85afd5eb27fe4b5d15d73bb7a7e4463d38 Mon Sep 17 00:00:00 2001 From: Russell Richie Date: Sun, 21 Jun 2026 18:32:18 -0400 Subject: [PATCH] Fix clear_cache() malformed .cols/.rows paths MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit clear_cache built the column/row fragment paths as f"{path}.cols{ext}" (missing the dot before the extension) for the existence check and f"{path}..cols.{ext}" (double dot) for removal — so the existence check never matched and the large .cols.parquet / .rows.parquet column-diff caches were silently left on disk. Use the correct {path}.cols.{ext} / {path}.rows.{ext} templates. Adds a regression test. Co-Authored-By: Claude Opus 4.8 --- openavmkit/utilities/cache.py | 8 ++++---- tests/test_clear_cache_paths.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/test_clear_cache_paths.py diff --git a/openavmkit/utilities/cache.py b/openavmkit/utilities/cache.py index b689f1b..fa83d41 100644 --- a/openavmkit/utilities/cache.py +++ b/openavmkit/utilities/cache.py @@ -157,10 +157,10 @@ def clear_cache(filename: str, filetype: str) -> None: path = f"cache/{filename}" if os.path.exists(f"{path}.{ext}"): os.remove(f"{path}.{ext}") - if os.path.exists(f"{path}.cols{ext}"): - os.remove(f"{path}..cols.{ext}") - if os.path.exists(f"{path}.rows{ext}"): - os.remove(f"{path}.rows{ext}") + if os.path.exists(f"{path}.cols.{ext}"): + os.remove(f"{path}.cols.{ext}") + if os.path.exists(f"{path}.rows.{ext}"): + os.remove(f"{path}.rows.{ext}") if os.path.exists(f"{path}.signature.json"): os.remove(f"{path}.signature.json") if os.path.exists(f"{path}.cols.signature.json"): diff --git a/tests/test_clear_cache_paths.py b/tests/test_clear_cache_paths.py new file mode 100644 index 0000000..923df07 --- /dev/null +++ b/tests/test_clear_cache_paths.py @@ -0,0 +1,32 @@ +import os + +from openavmkit.utilities.cache import clear_cache + + +def test_clear_cache_removes_cols_and_rows(tmp_path, monkeypatch): + """clear_cache must remove the .cols / .rows fragments and their signatures. + + Regression test: the path templates for the .cols/.rows data fragments were + malformed (missing dot in the existence check, double dot in the removal), + so clear_cache silently left the large .cols.parquet column-diff caches on + disk. Recreate every artifact a "df" cache entry produces and assert a clean + sweep. + """ + monkeypatch.chdir(tmp_path) + os.makedirs("cache", exist_ok=True) + + artifacts = [ + "foo.parquet", + "foo.cols.parquet", + "foo.rows.parquet", + "foo.signature.json", + "foo.cols.signature.json", + "foo.rows.signature.json", + ] + for name in artifacts: + open(os.path.join("cache", name), "w").close() + + clear_cache("foo", "df") + + for name in artifacts: + assert not os.path.exists(os.path.join("cache", name)), f"{name} was not removed"