Skip to content

fix: ensure contiguous spans in span_range with exact=True and month frame (#1185) - #1332

Open
deepakganesh78 wants to merge 1 commit into
arrow-py:masterfrom
deepakganesh78:fix/issue1185-span-range-month-gaps
Open

fix: ensure contiguous spans in span_range with exact=True and month frame (#1185)#1332
deepakganesh78 wants to merge 1 commit into
arrow-py:masterfrom
deepakganesh78:fix/issue1185-span-range-month-gaps

Conversation

@deepakganesh78

Copy link
Copy Markdown

Fixes #1185

Problem

span_range('month', start, end, exact=True) produces gaps (missing days) when the start day exceeds the number of days in a shorter month. For example, starting on Jan 31:

  • Span 1: Jan 31 → Feb 27
  • Span 2: Feb 28 → Mar 27
  • Span 3: Mar 31 → … ← Mar 28-30 are missing

Root cause

range() clips the day when shifting into a shorter month (Jan 31 → Feb 28) and later restores it when months are long enough again (→ Mar 31). Each span(exact=True) computes a one-month window from its iteration point, so the clipped Feb 28 produces a ceiling of Mar 27, while the restored Mar 31 becomes the next floor — leaving a 3-day gap.

Fix

Track the previous span's ceiling; when the next computed floor would leave a gap, substitute prev_ceil + 1 µs as the floor instead, ensuring every moment between start and end is covered by exactly one span.

Validation

  • Reproduction script confirms no gaps with the exact dates from the issue
  • New regression test test_exact_month_no_gaps_when_day_clipped added
  • Full test suite: 1901 passed, 2 skipped (pre-existing skips)

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…frame

When span_range iterates with frame='month' and exact=True, months with
fewer days cause day clipping in range() (e.g. Jan 31 -> Feb 28).  The
subsequent span(exact=True) computes the ceiling from the clipped date,
but range() restores the original day for the next iteration point,
leaving a multi-day gap between consecutive spans.

Fix: track the previous span's ceiling and use it (+1 µs) as the floor
of the next span whenever the computed floor would leave a gap.

Fixes arrow-py#1185

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.91%. Comparing base (2224255) to head (0a02d23).

Additional details and impacted files
@@             Coverage Diff             @@
##            master    #1332      +/-   ##
===========================================
- Coverage   100.00%   99.91%   -0.09%     
===========================================
  Files           10       10              
  Lines         2315     2321       +6     
  Branches       358      360       +2     
===========================================
+ Hits          2315     2319       +4     
- Misses           0        1       +1     
- Partials         0        1       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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.

span_range returns unexpected result (missing days) when using frame month

1 participant