← Back to Pull requests

[feature] Add a lock argument to cache_parquet #83

Closed
unknown closed this pull request without merging on Oct 20, 2026 20:58 UTC
View on GitHub
unknown unknown commented on Oct 19, 2026 17:26 UTC
Author

Description

Builds on #82; only the last commit is new here.

When several processes write to the same cache_parquet cache, each one that finds a partition missing or expired fetches it from upstream and writes it, so a cluster job can fetch the same data many times over. With ttl, this happens every time a file expires.

This adds a lock argument: a callable that takes the cache directory and returns a context manager. Only queries that may write take the lock: under CacheMode.CACHE when partitions are missing or expired, or when they cannot be enumerated, as for a query without date bounds; under CacheMode.REBUILD always. Once the lock is held, the query checks the cache again, so a process that waited reads what the other process wrote instead of fetching it. The lock is released before the cache is read. The library doesn't choose a locking mechanism, so callers can use whatever their storage supports.

from filelock import SoftFileLock

lf.piot.cache_parquet("/shared/cache/prices", "date", ttl=timedelta(hours=1),
                      lock=lambda d: SoftFileLock(d + ".lock"))

With two processes and a slow upstream, on NFS and on local disk, both processes fetch the same month without a lock. With SoftFileLock, the second process waits for the first and then reads from the cache without querying upstream.

A waiting process still queries upstream when its query has no date bound or is open at one end, because those queries always look for new partitions, and under CacheMode.REBUILD.

Type of Change

  • Bug fix

  • New feature

  • Documentation update

  • Refactor / code cleanup

  • CI / build configuration

  • Other (describe below)
  • Checklist

  • Linting passes (make lint-py, make lint-docs)

  • Tests pass (python -m pytest polars_io_tools/tests --ignore=polars_io_tools/tests/integration: 2024 passed with Polars 2.0.0, 2021 with Polars 1.44.1)

  • New tests added for new functionality

  • Documentation updated (if applicable)

  • Changelog / version bump (if applicable)
  • Diff: 260 lines (+195 / -65) across 3 files Reviewer: timkpaine Review duration: 1651m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 260 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.333
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #83"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.2% (MEDIUM) · Higher = larger blast radius
    39.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.5% · Safe to merge
    15.5%