Skip to content

Commit 1fe391c

Browse files
derek73claude
andcommitted
fix: correctly capitalize suffix acronyms written with dots (closes #141)
lc() strips only trailing periods, so 'M.D.' became 'm.d' which failed to match the dot-free exception key 'md'. Now also try the dot-stripped form when looking up capitalization exceptions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2373240 commit 1fe391c

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

nameparser/parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,8 @@ def cap_word(self, word: str, attribute: HumanNameAttributeT) -> str:
962962
exceptions = self.C.capitalization_exceptions
963963
if lc(word) in exceptions:
964964
return exceptions[lc(word)]
965+
if lc(word).replace('.', '') in exceptions:
966+
return exceptions[lc(word).replace('.', '')]
965967
mac_match = self.C.regexes.mac.match(word)
966968
if mac_match:
967969
def cap_after_mac(m: re.Match) -> str:

tests/test_capitalization.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ def test_capitalize_multiple_suffixes_still_split_correctly(self) -> None:
9393
hn.capitalize()
9494
self.assertEqual(hn.suffix_list, ['Ph.D.', 'M.D.'])
9595

96+
def test_capitalize_suffix_acronym_with_dots(self) -> None:
97+
# Suffixes already written with dots (e.g. "M.D.") should capitalize
98+
# to their exception form, not title-case to "M.d." (issue #141)
99+
hn = HumanName('GREGORY HOUSE M.D.')
100+
hn.capitalize()
101+
self.assertEqual(hn.suffix, 'M.D.')
102+
96103
# Leaving already-capitalized names alone
97104
def test_no_change_to_mixed_chase(self) -> None:
98105
hn = HumanName('Shirley Maclaine')

0 commit comments

Comments
 (0)