Repository navigation
Conversation
_contig_slice turns evenly spaced positions into a stepped slice, so iloc picks such as [0, 2, 4] or ::2 and boolean masks such as origin != "1985" passed the fancy-indexing check and built triangles with gaps between periods. get_idx, __setitem__ and _slice now accept only slices with a step of None, 1 or -1 on the origin and development axes and raise the existing fancy-indexing error otherwise. A step of -1 keeps adjacent periods and sort_axis relies on it. Two library paths pick every step-th development age on purpose. Grain conversion of a cumulative triangle and _slice_valuation pass a private allow_gaps flag to get_idx and keep their behavior. dropna compared the string labels of pattern triangles, so "120-132" sorted between "12-24" and "72-84". A JSON round trip of a fitted MunichAdjustment on the mcl sample therefore gave ldf_ nine columns with a gap instead of six. dropna now trims development by position. Refs casact#1649. Developed with an AI assistant (Árbol, running Muse).
scks1
requested review from
genedan,
henrydingliu and
kennethshsu
as code owners
November 19, 2026 16:50
Pyright Type CompletenessView the full Project (full
Other symbols referenced but not exported by
Symbols without documentation:
Patch (exported symbols added or changed by this PR): 0.0% fully typed (0 / 6)
Patch symbol details
|
Developed with an AI assistant (Árbol, running Muse).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1677 +/- ##
=======================================
Coverage 95.03% 95.04%
=======================================
Files 100 100
Lines 6471 6480 +9
Branches 819 821 +2
=======================================
+ Hits 6150 6159 +9
Misses 203 203
Partials 118 118
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
This PR fixes the slicing bug from #1649. The origin dtype check in
_compatibility_checkstays a separate fix._contig_sliceturns evenly spaced positions into a stepped slice. The check inget_idxonly asked whether the origin and development keys were slices, so[0, 2, 4]and::2passed. Boolean masks go through_slice, which had no check, soraa[raa.origin != "1985"]returned a triangle with a missing year. Each of these built a triangle with gaps between periods.The PR adds
_LocBase._is_unit_slice. It accepts a slice with a step of None, 1 or -1.get_idx,__setitem__and_sliceuse it on the origin and development axes and raise the existing fancy-indexing error for anything else. A step of -1 keeps adjacent periods in reverse order, andsort_axisand its tests rely on it.Two library paths pick every step-th development age on purpose. Grain conversion of a cumulative triangle keeps every fourth age to go from quarterly to annual development, and
_slice_valuationserves valuation masks andlatest_diagonal. Both pass a privateallow_gaps=Truetoget_idxand keep their behavior. Valuation masks therefore work as on main.The stricter check also turned up a gap in
dropna. It compared the string labels of pattern triangles, so"120-132"sorted between"12-24"and"72-84". A JSON round trip of a fittedMunichAdjustmentonmclgaveldf_nine columns with a gap instead of six.dropnanow trims development by position.Related GitHub Issue(s)
Refs #1649
AI/LLM Usage
This change was made with Árbol, an AI assistant running on Muse, working under my direction. It wrote the fix and the tests, ran the checks below and drafted this description.
Additional Context for Reviewers
raailoc[..., ::2, :]iloc[..., [0, 2, 4], :]iloc[..., ::-1, :]iloc[..., :, ::2]raa[raa.origin != "1985"]raa[raa.development % 24 == 0]raa[raa.origin >= "1985"]On this branch the script prints
and on main it prints
Code
dropnagap on main shows up in a JSON round trip.On this branch both lines read
['12-24', '24-36', '36-48', '48-60', '60-72', '72-84'].Code
New tests in
test_slicing.pycover steppedilockeys on both axes, non-contiguous boolean masks, a contiguous mask, setting through stepped keys, reversal, and quarterly to annual grain.test_json_pattern_keeps_developmentintest_utilities.pycovers thedropnagap. The full suite gives 1756 passed and 9 skipped on this branch, against 1739 passed and 9 skipped on main.Two questions for you. Should reversed
::-1slices stay allowed? Should user-facing stepped development picks such asiloc[..., :, ::2]raise, or should they stay open for users who want a coarser view?Submitter's Checklist
[FIX],[FEAT],[DOCS],[TST],[CHORE], or[BRK]).Reviewer's Checklist