-
Notifications
You must be signed in to change notification settings - Fork 490
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
Comments
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 … |
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 |
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). |
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? |
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 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. |
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! |
Thinking further about it, we could use: subdivisions_aliases = {
"B": "1",
"K": "2",
"N": "3",
"NÖ": "3",
"Niederösterreich": "3",
...
} Quick lookup vs. readability … |
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? |
Same idea at the same time! 😅 |
@sphh thank you for taking care of this! |
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.
The text was updated successfully, but these errors were encountered: