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
{{ message }}
Repository navigation
ordinal() emits wrong suffixes for negative integers #536
The docstring says ordinal "works for any integer". The implementation uses value % 10 (and % 100 for the teen exception), which yields negative residues for negative inputs in Python only when... actually Python's % returns non-negative residues, but the comparisons against positive literals 1/2/3 and the 11-13 teen exception don't align for negative operands, so negatives ending in 1/2/3 (outside the exception window) all fall through to 'th'.
If this behavior is unwanted, I’d be happy to open a small PR applying the suffix selection to abs(value), with regression tests for negative values ending in 1/2/3 and the teen exceptions. I’ll wait for maintainer direction before proceeding.
You’re right to question it. I checked for duplicates: I don’t see an earlier issue for this exact behavior, but there have already been multiple PR attempts, including PR 405 still open and PR 321 closed, where the same semantic concern was raised. I don’t have a compelling real-world use for “-1st”; I was reading “any integer” in the docstring too literally. I’ll close this rather than add more duplicate noise. Thanks for the correction.
Activity
SonicHedghog commentedon Dec 2, 2026
If this behavior is unwanted, I’d be happy to open a small PR applying the suffix selection to
abs(value), with regression tests for negative values ending in 1/2/3 and the teen exceptions. I’ll wait for maintainer direction before proceeding.hugovk commentedon Dec 2, 2026
What does "-1st" even mean? Please check for duplicate issues and PRs.
SonicHedghog commentedon Dec 2, 2026
You’re right to question it. I checked for duplicates: I don’t see an earlier issue for this exact behavior, but there have already been multiple PR attempts, including PR 405 still open and PR 321 closed, where the same semantic concern was raised. I don’t have a compelling real-world use for “-1st”; I was reading “any integer” in the docstring too literally. I’ll close this rather than add more duplicate noise. Thanks for the correction.