Skip to content

Fix ordinal suffix generation for large numbers ending in 11, 12, 13 - #556

Merged
mergify[bot] merged 1 commit into
jd:mainfrom
ArmaanjeetSandhu:fix/ordinal-suffix-logic
Feb 17, 2026
Merged

mergify[bot] merged 1 commit into
jd:mainfrom
ArmaanjeetSandhu:fix/ordinal-suffix-logic

Conversation

@ArmaanjeetSandhu

Copy link
Copy Markdown
Contributor

This PR fixes a logical error in the _utils.find_ordinal helper where numbers greater than 20 ending in 11, 12, or 13 were incorrectly suffixed.

The Issue:
Previously, the code checked for the 11–13 exception range only on the raw number. For numbers > 20, it recursed using num % 10.

  • Input: 111
  • Old Logic: 111 > 20 -> recurse find_ordinal(1) -> returns "st" -> Output: "111st" (Incorrect)

The Fix:
Added a check for pos_num % 100 to catch the 11–13 pattern for larger numbers before recursing.

  • New Logic: 111 % 100 is 11 -> returns "th" -> Output: "111th" (Correct)

Changes:

  • Modified tenacity/_utils.py: Added modulo 100 check.
  • Updated tests/test_utils.py: Added specific test cases for 111, 112, and 113.

The `find_ordinal` utility incorrectly assigned "st", "nd", and "rd" suffixes to numbers greater than 20 that end in 11, 12, or 13 (e.g., 111 became "111st").

This commit modifies the logic to check `pos_num % 100` for the 11–13 range before falling back to the modulo 10 recursion. This ensures consistent "th" suffixes for these edge cases (e.g., "111th", "112th").

New regression tests have been added to `tests/test_utils.py` to cover these scenarios.
@mergify
mergify Bot merged commit 0bdf1d9 into jd:main Feb 17, 2026
9 checks passed
@mergify

mergify Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Merge Queue Status

Rule: default


  • ✅ Entered queue — 2026-02-17 08:30 UTC
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-02-17 08:31 UTC · at 086abc5443b5664be1a977b5718c246d58e5f145

This pull request spent 25 seconds in the queue, including 4 seconds running CI.

Required conditions to merge

@ArmaanjeetSandhu
ArmaanjeetSandhu deleted the fix/ordinal-suffix-logic branch February 17, 2026 08:33
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.

2 participants