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
Thank you for this PR and improving the library. Changing 'یکم' to 'اول' for the number 1 in ordinal mode is a great idea since "اول" is more commonly used in Persian.
✅ Strengths
Changes in ordinal_suffix.py: Adding support for 'اول' and 'اولین' in the add() and remove() functions is done correctly.
Adding mapping in strings.py: Adding "اول": "یک" to TYPO_LIST for reverse conversion support is good.
Comprehensive tests: The added tests provide good coverage for various cases.
⚠️ Issues Identified
Issue 1: number == 1 check without considering the ordinal parameter
In your changes to persian_tools/digits/__init__.py, this code was added:
Problem: This code always returns "اول" even when ordinal=False! This causes convert_to_word(1, ordinal=False) to return "اول" instead of "یک", which is incorrect.
Suggested Solution:
The best approach is to perform this check after complete processing and before adding the ordinal suffix:
ifnumber==0:
return'صفر'is_negative=number<0number=abs(number)
# ... rest of the processing (lines 69-91) ...words=words.strip()
ifis_negative:
words='منفی '+wordsifordinal:
# Special case: 1 should be "اول" not "یکم"ifwords=='یک'orwords=='منفی یک':
words=words.replace('یک', 'اول')
else:
words=add_ordinal_suffix(words)
returnwords
Important Note: Actually, the changes you made in ordinal_suffix.py (ordinal_suffix.add('یک') → 'اول') are sufficient! When convert_to_word(1, ordinal=True) is called, it first generates "یک" and then calls add_ordinal_suffix('یک'), which with your changes returns "اول". So there's no need for an additional check in digits/__init__.py and you can remove it.
Issue 2: Lack of support for negative numbers
If number == -1 and ordinal=True, it should return "منفی اول". The current changes don't account for this case.
Issue 3: Processing order
The number == 1 check should be performed after abs(number) to also cover negative numbers.
🔍 Review of Existing Tests
Existing tests that might be affected:
test_convert_to_word(): If convert_to_word(1) is called without ordinal=True, it should return "یک" not "اول"
📝 Suggestions
Fix the number == 1 check: Should only apply when ordinal=True
Support for negative numbers: Should also support "منفی اول"
Additional test: Add a test for convert_to_word(1, ordinal=False) which should return "یک"
Test for negative numbers: Add a test for convert_to_word(-1, ordinal=True) which should return "منفی اول"
✨ Conclusion
The PR idea is excellent and the changes in ordinal_suffix.py and strings.py are correct, but needs correction in digits/__init__.py to only apply in ordinal mode.
Thank you for this improvement! 🙏
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Persian, we often use "اول" instead of "یکم". For example, "گل اول رو زد" or "اولین قسمت منتشر شد"