Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement subdivision aliases support #1660

Closed
arkid15r opened this issue Jan 23, 2024 · 10 comments · Fixed by #1662
Closed

Implement subdivision aliases support #1660

arkid15r opened this issue Jan 23, 2024 · 10 comments · Fixed by #1662
Assignees

Comments

@arkid15r
Copy link
Collaborator

Per #1656 discussion it'd be great to have an ability to assign aliases to ISO3166-2 subdivision codes.

Let's figure out complexity and priority of the task (v0 vs v1) and implement this feature. It would provide better user experience.

@sphh
Copy link
Contributor

sphh commented Jan 23, 2024

BTW I could help implementing this, but I noticed that you seem to have very strict ideas, how the API should work and I guess also how it should be implemented. If you don't have the time to do it yourself and you give me some valuable hints, I could help out …

@arkid15r
Copy link
Collaborator Author

Yeah, that'd be much appreciated.

The main priority for the current PH version is compatibility. This may be the reason for the seemed strictness you've mentioned. Then goes performance and code readability. Those are sort of my promises to previous code author/maintainer.

We've started working on v1 of the library. If you have improvement ideas or with to participate in some other way -- check out #1649

@arkid15r
Copy link
Collaborator Author

In other words the only strict requirement for any contribution is compatible and well tested code made right from performance perspective (we have ~5M monthly downloads relying on that).

@sphh
Copy link
Contributor

sphh commented Jan 23, 2024

I can have a go, if you like. Three different approaches come do mind (all without in-depth investigation): Using a dictionary, where the key is the official ISO code and the value a tuple of all aliases. Secondly, use a tuple with a tuple for each subregion, where the first element is the official ISO code and all other elements aliases. And finally keep the subregion tuple as it is and have a separate dictionary with the aliases. Any preferences?

@arkid15r
Copy link
Collaborator Author

The idea with mapping is right -- use alias subdiv as a key and iso3166 code as a value:

subdivisions_aliases = {
    "B": "1",
    "K": "2",
    ...
}

This way you'd have average O(1) lookup. Then just swap alias to an official subdiv code at right place of HolidayBase::init. I guess that would be it (no in-depth investigation as well). You'll need to update TestArgs::test_subiv of tests/test_holiday_base.py to make sure it works as expected.

An apparent drawback of this simple approach is that the holidays object would have the subdiv code implicitly changed from the user perspective.

Just create a PR or use this thread for further questions if any.

@sphh
Copy link
Contributor

sphh commented Jan 23, 2024

I also thought about this approach, because of the same reason: the quick lookup. The reason why I did not propose it, was the other major drawback: You are limited to just one alias. In the Austrian case: You can only use 'N', but not 'NÖ' or even 'Niederösterreich', all valid and widely used aliases for the subregion 3!

@sphh
Copy link
Contributor

sphh commented Jan 23, 2024

Thinking further about it, we could use:

subdivisions_aliases = {
    "B": "1",
    "K": "2",
    "N": "3",
    "NÖ": "3",
    "Niederösterreich": "3",
    ...
}

Quick lookup vs. readability …

@arkid15r
Copy link
Collaborator Author

I believe that wouldn't be the case:

subdivisions_aliases = {
    "N": "3",
    "NÖ": "3",
    "Niederösterreich": "3"
}

All mapped to "3". Am I missing something?

@sphh
Copy link
Contributor

sphh commented Jan 23, 2024

Same idea at the same time! 😅

@arkid15r
Copy link
Collaborator Author

@sphh thank you for taking care of this!

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 a pull request may close this issue.

2 participants