Skip to content

Fix IndexError converting 0 to ordinal in Polish and Ukrainian#668

Open
santhreal wants to merge 1 commit into
savoirfairelinux:masterfrom
santhreal:fix/ordinal-zero-indexerror-pl-uk
Open

Fix IndexError converting 0 to ordinal in Polish and Ukrainian#668
santhreal wants to merge 1 commit into
savoirfairelinux:masterfrom
santhreal:fix/ordinal-zero-indexerror-pl-uk

Conversation

@santhreal

Copy link
Copy Markdown

num2words(0, lang='pl', to='ordinal') and lang='uk' raise IndexError: list index out of range.

to_ordinal splits the number into 3-digit fragments and pops trailing all-zero fragments; for 0 that empties the list and the next fragments[-1] raises. Both languages return correct ordinals for every other integer (1 -> pierwszy/перший, 100 -> setny/сотий), and en/ru/de/fr already return a zero ordinal, so return the zero ordinal (zerowy / нульовий) which matches each module's masculine-nominative convention.

Same bug class as #661 (Mongolian); this covers Polish and Ukrainian. Adds a regression case to each language's ordinal test.

to_ordinal split the number into 3-digit fragments and popped trailing
zero fragments, but for 0 that emptied the list and the next index raised
IndexError. Both languages already support ordinals for every other
integer, so return the zero ordinal (zerowy / нульовий) instead.
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