You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'>]
The text was updated successfully, but these errors were encountered:
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
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).
The first error is
IndexError
:The second one is
InvalidOperation
:The text was updated successfully, but these errors were encountered: