Repository navigation
Description
Description
There are a bunch of places where the grain is looked up using a hardcoded dictionary. For example:
chainladder-python/chainladder/tails/curve.py
Line 190 in 6f80200
| grain = {"Y": 12, "S": 6, "Q": 3, "M": 1}[X.development_grain] |
There are some clues in the docs that indicate that the supported grain types have changed over time. For example, A used to be allowed for yearly grain. For semiannual grain, S seems to be the supported value, although there are places where I see 2Q used, so it's not clear to me what the status is (or what the purpose of 2Q might be).
Should the supported grain ever be changed again, we'd have to find all the scattered locations of these dictionaries and update them. Storing a unified dict in a central location and then importing it will improve maintainability.
Is your feature request aligned with the scope of the package?
- Yes, absolutely!
- No, but it's still worth discussing.
- N/A (this request is not a codebase enhancement).
Describe the solution you'd like, or your current workaround.
{"Y": 12, "S": 6, "Q": 3, "M": 1} Should be stored somewhere central, maybe in __init__.py? Something like:
__grain_to_months__ = {"Y": 12, "S": 6, "Q": 3, "M": 1}
But I'm open to better ideas/names.
Do you have any additional supporting notes?
No response
Would you be willing to contribute this ticket?
- Yes, absolutely!
- Yes, but I would like some help.
- No.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Scope
Effort
Projects
- StatusShow more project fieldsReady
Activity
henrydingliu commentedon Jul 10, 2026
I recall 2Q is a frequency parameter for Pandas.
henrydingliu commentedon Oct 11, 2026
there is also
Triangle._dstepscks1 commentedon Nov 13, 2026
I'd like to take this. Open PR #1304 also edits several of the grain lookups this would move (for example in
core/common.pyandcore/axis.py), and #1480 changes_dstepcall sites. Should I wait for #1304 to merge, or open a PR against main now and rebase afterward?(This comment was written with Árbol, an AI assistant, under my direction.)
henrydingliu commentedon Nov 14, 2026
do you think a reasonable first step would be to simply implement the centralized grain value? then we can migrate rogue grain lists to the central location over time
scks1 commentedon Nov 14, 2026
Yes, that sounds right. My plan for the first PR:
__grain_to_months__ = {"Y": 12, "S": 6, "Q": 3, "M": 1}(the name from the issue) tochainladder/_config/options.py, next to__dt64_unit__, with a test.development/learning.pyto it, since no open PR touches that file. The other lists move later, as the open PRs that edit their files (mainly [FEAT]deprecate date dims #1304) merge.Does
_configwork for you, or would you rather it live somewhere else?(This comment was written with Árbol, an AI assistant, under my direction.)
[CHORE] Remove grain constant tests
[CHORE] Centralize grain values in _config
[CHORE] Remove grain constant tests