Skip to content

Centralize supported grain values #1050

Open

Description

@genedan

Description

There are a bunch of places where the grain is looked up using a hardcoded dictionary. For example:

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.

Activity

  1. henrydingliu commented on Jul 10, 2026

    @henrydingliu
    Member

    I recall 2Q is a frequency parameter for Pandas.

  2. added this to the v0.11.0 milestone on Sep 20, 2026
  3. moved this from Not Ready to Ready in Chainladder-Python Project Boardon Sep 20, 2026
  4. added
    Great First Contribution! 🌱Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!
    and removed on Sep 20, 2026
  5. updated Priority Low, Scope Codebase and Effort Low on Sep 20, 2026
  6. henrydingliu commented on Oct 11, 2026

    @henrydingliu
    Member

    there is also Triangle._dstep

  7. scks1 commented on Nov 13, 2026

    @scks1
    Contributor

    I'd like to take this. Open PR #1304 also edits several of the grain lookups this would move (for example in core/common.py and core/axis.py), and #1480 changes _dstep call 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.)

  8. henrydingliu commented on Nov 14, 2026

    @henrydingliu
    Member

    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

  9. scks1 commented on Nov 14, 2026

    @scks1
    Contributor

    Yes, that sounds right. My plan for the first PR:

    • Add __grain_to_months__ = {"Y": 12, "S": 6, "Q": 3, "M": 1} (the name from the issue) to chainladder/_config/options.py, next to __dt64_unit__, with a test.
    • Switch the four lookups in development/learning.py to 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 _config work for you, or would you rather it live somewhere else?

    (This comment was written with Árbol, an AI assistant, under my direction.)

  10. added a commit that references this issue on Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Great First Contribution! 🌱Beginner friendly tickets with narrow scope and huge impact. Perfect to get your feet wet!

    Type

    No type

    Fields

    Priority

    Low

    Scope

    Codebase

    Effort

    Low

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions