Skip to content

feat(features): lower ReplenishmentConfig count_window_days floor to 3 (#113)#122

Merged
w7-mgfcode merged 1 commit into
devfrom
feat/features-replenishment-count-window-floor
May 14, 2026
Merged

feat(features): lower ReplenishmentConfig count_window_days floor to 3 (#113)#122
w7-mgfcode merged 1 commit into
devfrom
feat/features-replenishment-count-window-floor

Conversation

@w7-mgfcode
Copy link
Copy Markdown
Owner

@w7-mgfcode w7-mgfcode commented May 14, 2026

Summary

Closes #113. Aligns ReplenishmentConfig.count_window_days floor with PRP-3.1C's original pseudocode intent (W=3) — PRP-3.1A's ge=7 was set without recorded rationale, forcing the leakage test test_count_window_uses_shift_then_rolling to use W=7 instead of the W=3 probe the PRP described.

Diff

  • schemas.pycount_window_days = Field(default=14, ge=3, le=60) (was ge=7); docstring range comment (7-60)(3-60).
  • test_schemas.py — boundary test now probes count_window_days=2 to verify the new floor (previously =6).
  • test_leakage.py — docstring updated to drop the stale "smallest window the config schema allows" claim; test body unchanged (still uses W=7, which now sits comfortably above the floor).
  • docs/PHASE/3-FEATURE_ENGINEERING.md — inline range comment # 7..60# 3..60.

Test plan

  • uv run ruff check app/features/featuresets/ — clean
  • uv run ruff format --check app/features/featuresets/ — 11 files already formatted
  • uv run mypy app/ — 0 issues in 192 files
  • uv run pyright app/features/featuresets/ — 0 errors
  • uv run pytest app/features/featuresets/ -m "not integration" — 108 passed
  • uv run pytest -m "not integration" — 962 passed (full unit sweep)
  • CI gates green (Lint & Format, Type Check, Test, Migration Check)

Notes for the reviewer

  • No behavioral regression — every existing call site already uses W=7 or W=14, both still valid under ge=3. The change is purely an input-range expansion.
  • Why W=3 is mathematically validshift(1).rolling(W, min_periods=1).sum() works for any W >= 1. W=3 is the smallest window that can detect a cadence trend (W=1 is just shift(1), W=2 is the minimum smoothing). Sub-weekly cadence windows are meaningful for retailers with daily replenishment.
  • Why test_leakage.py logic unchanged — the leakage probe asserts the shift(1).rolling(W).count() ordering, not the floor. W=7 still demonstrates the math; only the docstring's parenthetical needed updating.
  • PRP files left untouched — PRP-3.1A and PRP-3.1C are historical design contracts at implementation time. The schema + tests + DEV-facing docs are the new source of truth.

Out of scope

  • Touching _compute_replenishment_features math (per the issue's "Out of scope").
  • test_leakage.py::TestReplenishmentLeakage invariants (untouched).

Summary by Sourcery

Lower the minimum allowed replenishment count window to broaden configuration options while keeping existing behavior intact.

New Features:

  • Allow ReplenishmentConfig.count_window_days values down to 3 days instead of 7.

Enhancements:

  • Update validation tests to reflect the new count_window_days lower bound.
  • Refresh test and feature-engineering documentation to accurately describe the new count_window_days range and clarify leakage test commentary.

#113)

PRP-3.1C's pseudocode originally referenced W=3 as the smallest
meaningful trailing window for replenishment-count features, but
PRP-3.1A's schema set `ge=7` with no recorded rationale. The mismatch
forced `test_count_window_uses_shift_then_rolling` to use W=7 instead
of the original W=3 probe.

This change aligns the schema with PRP-3.1C's intent:
- `count_window_days = Field(default=14, ge=3, le=60)` (was `ge=7`)
- Update boundary test to probe the new floor (count_window_days=2)
- Refresh leakage-test docstring and docs/PHASE/3 range comment

All existing call sites already use W=7 or W=14, so no behavioral
regression. `shift(1).rolling(W, min_periods=1).sum()` works for any
W>=1; W=3 is the smallest window that can detect a cadence trend.

Closes #113.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dee6ad35-6cd2-4a1b-a516-38d137ba1c9d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/features-replenishment-count-window-floor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 14, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Lowers the minimum allowed ReplenishmentConfig.count_window_days from 7 to 3 and updates validation tests, leakage-test documentation, and feature-engineering docs to match the expanded configuration range.

File-Level Changes

Change Details Files
Relaxed the ReplenishmentConfig.count_window_days lower bound from 7 to 3.
  • Updated the Pydantic Field for count_window_days to use ge=3 instead of ge=7 while keeping default=14 and le=60.
  • Adjusted the ReplenishmentConfig docstring comment to state the valid range as 3-60 instead of 7-60.
app/features/featuresets/schemas.py
Aligned tests with the new count_window_days floor of 3.
  • Updated the boundary validation test to describe a minimum of 3 days instead of 7.
  • Changed the invalid value used in the below-min test from 6 to 2 to stay strictly under the new floor.
app/features/featuresets/tests/test_schemas.py
Clarified the leakage test documentation to decouple it from the old minimum window size.
  • Reworded the leakage test docstring so that W=7 is described as being above the ReplenishmentConfig floor of 3 rather than as the smallest allowed window.
  • Left the test logic and parameter W=7 unchanged, since it still exercises the shift+rolling ordering invariant.
app/features/featuresets/tests/test_leakage.py
Updated developer-facing feature-engineering documentation to reflect the new count_window_days range.
  • Changed the inline comment in the ReplenishmentConfig example to show the valid range as 3..60 instead of 7..60.
docs/PHASE/3-FEATURE_ENGINEERING.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The min/max bounds for count_window_days (3 and 60) are currently duplicated across the schema docstring, tests, and docs; consider centralizing these values (e.g., as module-level constants or config) to reduce the chance of future range changes getting out of sync.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The min/max bounds for `count_window_days` (3 and 60) are currently duplicated across the schema docstring, tests, and docs; consider centralizing these values (e.g., as module-level constants or config) to reduce the chance of future range changes getting out of sync.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@w7-mgfcode w7-mgfcode merged commit 42c9fb8 into dev May 14, 2026
8 checks passed
@w7-mgfcode w7-mgfcode deleted the feat/features-replenishment-count-window-floor branch May 18, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant