Skip to content

Commit b72adf6

Browse files
derek73claude
andcommitted
fix: recognize single-letter suffix_not_acronyms (e.g. 'V') in suffix-comma format (closes #136)
Roman numeral suffixes like 'V' are single uppercase letters, which the initial regex also matches. In suffix-comma format ("John Ingram, V") the post-comma position is unambiguous, so the initial guard should not block recognition. Add are_suffixes_after_comma() that bypasses the initial check for suffix_not_acronyms members and use it at the suffix-comma detection site, leaving is_suffix() unchanged for the no-comma path where 'V' mid-name should still be treated as an initial. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1fe391c commit b72adf6

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

nameparser/parser.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,21 @@ def are_suffixes(self, pieces: Iterable[str]) -> bool:
487487
return False
488488
return True
489489

490+
def are_suffixes_after_comma(self, pieces: Iterable[str]) -> bool:
491+
"""Like are_suffixes but suffix_not_acronyms members are always
492+
recognized, even when they look like single-letter initials.
493+
494+
Used when detecting suffix-comma format (e.g. "John Ingram, V") where
495+
the post-comma position is unambiguous: a single uppercase roman
496+
numeral like 'V' is definitionally a suffix there, not an initial.
497+
"""
498+
for piece in pieces:
499+
if lc(piece) in self.C.suffix_not_acronyms:
500+
continue
501+
if not self.is_suffix(piece):
502+
return False
503+
return True
504+
490505
def is_rootname(self, piece: str) -> bool:
491506
"""
492507
Is not a known title, suffix or prefix. Just first, middle, last names.
@@ -686,7 +701,7 @@ def parse_full_name(self) -> None:
686701

687702
post_comma_pieces = self.parse_pieces(parts[1].split(' '), 1)
688703

689-
if self.are_suffixes(parts[1].split(' ')) \
704+
if self.are_suffixes_after_comma(parts[1].split(' ')) \
690705
and len(parts[0].split(' ')) > 1:
691706

692707
# suffix comma:

tests/test_suffixes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ def test_two_suffixes_lastname_comma_format(self) -> None:
3434
# NOTE: this adds a comma when the original format did not have one.
3535
self.m(hn.suffix, "Jr., MD", hn)
3636

37+
def test_roman_numeral_v_suffix_comma_format(self) -> None:
38+
# 'V' is a single uppercase letter, so it was incorrectly matched as an
39+
# initial and not recognized as a suffix (issue #136)
40+
hn = HumanName("John W. Ingram, V")
41+
self.m(hn.first, "John", hn)
42+
self.m(hn.middle, "W.", hn)
43+
self.m(hn.last, "Ingram", hn)
44+
self.m(hn.suffix, "V", hn)
45+
3746
def test_two_suffixes_suffix_comma_format(self) -> None:
3847
hn = HumanName("Franklin Washington, Jr. MD")
3948
self.m(hn.first, "Franklin", hn)

0 commit comments

Comments
 (0)