Skip to content

Fix KeyError in Catalan to_ordinal for exact tens#670

Open
santhreal wants to merge 1 commit into
savoirfairelinux:masterfrom
santhreal:fix/ca-ordinal-tens-keyerror
Open

Fix KeyError in Catalan to_ordinal for exact tens#670
santhreal wants to merge 1 commit into
savoirfairelinux:masterfrom
santhreal:fix/ca-ordinal-tens-keyerror

Conversation

@santhreal

Copy link
Copy Markdown

Catalan to_ordinal builds the tens ordinals (30, 40, ..., 90) by appending a units part looked up in self.ords_3, which only has keys 1-9. For an exact multiple of ten the units index is 0, so self.ords_3[0] raises KeyError: 0. Every higher ordinal that recurses through a whole ten crashes too (for example to_ordinal(130) -> "cent " + to_ordinal(30)).

>>> num2words(30, lang="ca", to="ordinal")
KeyError: 0

When there is no units part, emit the tens stem plus the gender suffix ("trentè", "quarantè", ...), matching how 20 ("vintè") and 100 ("centè") are already handled. Unit-tens ordinals like 33 ("trenta-tresè") are unchanged. Added the previously missing exact-tens cases to the ordinal test data.

to_ordinal built the tens ordinals (30, 40, ..., 90) by appending a
units part looked up in self.ords_3, which only has keys 1-9. For an
exact multiple of ten the units index is 0, so self.ords_3[0] raised
KeyError: 0. This also broke every higher ordinal that recurses through
a whole ten (for example 130 -> "cent trentè").

Emit the tens ordinal as the tens stem plus the gender suffix when there
is no units part, matching how 20 ("vintè") and 100 ("centè") are
already handled. Add the previously missing exact-tens cases to the
ordinal test data.
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 this pull request may close these issues.

1 participant