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

Arabic: num2words(..., lang="ar") can fail with IndexError or InvalidOperation (instead of OverflowError) #511

Closed
Jeronymous opened this issue Mar 29, 2023 · 0 comments

Comments

@Jeronymous
Copy link
Contributor

Expected Behaviour

num2words can sometimes fail with OverflowError on big numbers, that's fine.

But sometimes for Arabic language, it fails with other errors that seem to be bugs.

Actual Behaviour / Steps to reproduce

Here are two input which fails, with 2 different errors (IndexError / InvalidOperation).

from num2words import num2words

num2words(55772955305950220940549447929, lang="ar")

num2words(5577295530595022094054944792999999, lang="ar")

The first error is IndexError:

File ~/.local/lib/python3.10/site-packages/num2words/__init__.py:98, in num2words(number, ordinal, lang, to, **kwargs)
#      95 if to not in CONVERTES_TYPES:
#      96     raise NotImplementedError()
# ---> 98 return getattr(converter, 'to_{}'.format(to))(number, **kwargs)

# File ~/.local/lib/python3.10/site-packages/num2words/lang_AR.py:352, in Num2Word_AR.to_cardinal(self, number)
#     350 self.arabicSuffixText = ""
#     351 self.arabicOnes = ARABIC_ONES
# --> 352 return minus + self.convert(value=abs(number)).strip()

# File ~/.local/lib/python3.10/site-packages/num2words/lang_AR.py:205, in Num2Word_AR.convert(self, value)
#     203 self.number = "{:.9f}".format(value)
#     204 self.number_to_arabic(self.arabicPrefixText, self.arabicSuffixText)
# --> 205 return self.convert_to_arabic()

# File ~/.local/lib/python3.10/site-packages/num2words/lang_AR.py:241, in Num2Word_AR.convert_to_arabic(self)
#     238 else:
#     239     if ret_val != "":
#     240         ret_val = "{} {}".format(
# --> 241             self.arabicAppendedGroup[group],
#     242             ret_val)
#     243     else:
#     244         ret_val = "{} {}".format(
#     245             self.arabicGroup[group], ret_val)

# IndexError: list index out of range

The second one is InvalidOperation:

# ile ~/.local/lib/python3.10/site-packages/num2words/__init__.py:98, in num2words(number, ordinal, lang, to, **kwargs)
#      95 if to not in CONVERTES_TYPES:
#      96     raise NotImplementedError()
# ---> 98 return getattr(converter, 'to_{}'.format(to))(number, **kwargs)

# File ~/.local/lib/python3.10/site-packages/num2words/lang_AR.py:352, in Num2Word_AR.to_cardinal(self, number)
#     350 self.arabicSuffixText = ""
#     351 self.arabicOnes = ARABIC_ONES
# --> 352 return minus + self.convert(value=abs(number)).strip()

# File ~/.local/lib/python3.10/site-packages/num2words/lang_AR.py:205, in Num2Word_AR.convert(self, value)
#     203 self.number = "{:.9f}".format(value)
#     204 self.number_to_arabic(self.arabicPrefixText, self.arabicSuffixText)
# --> 205 return self.convert_to_arabic()

# File ~/.local/lib/python3.10/site-packages/num2words/lang_AR.py:222, in Num2Word_AR.convert_to_arabic(self)
#     217 group = 0
#     219 while temp_number > Decimal(0):
#     221     number_to_process = int(
# --> 222         Decimal(str(temp_number)) % Decimal(str(1000)))
#     223     temp_number = int(Decimal(temp_number) / Decimal(1000))
#     225     group_description = \
#     226         self.process_arabic_group(number_to_process,
#     227                                   group,
#     228                                   Decimal(floor(temp_number)))

# InvalidOperation: [<class 'decimal.DivisionImpossible'>]

@Jeronymous Jeronymous changed the title num2words(..., lang="ar") can fail with IndexError or InvalidOperation Arabic: num2words(..., lang="ar") can fail with IndexError or InvalidOperation (instead of OverflowError) Mar 29, 2023
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

No branches or pull requests

1 participant