Skip to content

feat: add suffix_delimiter for parsing suffixes separated by arbitrary delimiters (#156)#172

Merged
derek73 merged 10 commits into
masterfrom
fix/issue-156-suffix-delimiter
Jun 29, 2026
Merged

feat: add suffix_delimiter for parsing suffixes separated by arbitrary delimiters (#156)#172
derek73 merged 10 commits into
masterfrom
fix/issue-156-suffix-delimiter

Conversation

@derek73

@derek73 derek73 commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds suffix_delimiter to Constants (default None) and as a HumanName kwarg, following the same pattern as initials_separator
  • After splitting on commas, re-splits parts[1:] on suffix_delimiter and flattens — turning "RN - CRNA" into two separate suffix tokens with no changes to downstream parse logic
  • Names like "Steven Hardman, RN - CRNA" now parse correctly when suffix_delimiter=" - " is set

Usage

# Per-instance
HumanName("Steven Hardman, RN - CRNA", suffix_delimiter=" - ")

# Global default
from nameparser.config import CONSTANTS
CONSTANTS.suffix_delimiter = " - "

Test Plan

  • HumanName("Steven Hardman, RN - CRNA", suffix_delimiter=" - ")first="Steven", last="Hardman", suffix="RN, CRNA"
  • Multiple delimiters: "John Doe, MD - PhD - FACS"suffix="MD, PhD, FACS"
  • CONSTANTS.suffix_delimiter applies globally to new instances
  • Default behavior (no delimiter) unchanged — existing tests all pass
  • uv run pytest — 748 passed, 20 xfailed

Closes #156

🤖 Generated with Claude Code

derek73 and others added 10 commits June 28, 2026 19:50
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add the suffix_delimiter class attribute to the Constants class with a default
value of None. This attribute will be used by HumanName to split suffix groups
after comma-splitting. The attribute follows the existing pattern of scalar
class attributes (string_format, initials_delimiter, initials_separator).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When parsing names with suffixes separated by a custom delimiter (e.g.
"Steven Hardman, RN - CRNA" with suffix_delimiter=" - "), the parser
now re-splits post-comma parts on the suffix_delimiter and flattens them
before processing. This transforms ["Steven Hardman", "RN - CRNA"] into
["Steven Hardman", "RN", "CRNA"], making downstream suffix detection work
correctly instead of treating the delimiter as an invalid suffix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…clarify known-limitation test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Filter empty tokens from trailing/leading delimiters to prevent
  silent parse corruption (e.g. "MD-PhD-" with suffix_delimiter="-")
- Clarify no-op note in Constants docstring: both the comma split and
  subsequent strip() make ", " a no-op, not just the comma split
- Correct param docstring: expansion applies to all post-comma parts,
  not just identified suffix groups
- Tighten known-limitation test with concrete field assertions instead
  of a fragile assertNotEqual
- Add tests: trailing delimiter, comma-space no-op, inverted-format
  limitation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@derek73 derek73 merged commit 2fb327c into master Jun 29, 2026
8 checks passed
@derek73 derek73 deleted the fix/issue-156-suffix-delimiter branch June 29, 2026 05:14
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.

Handling " - " separators in suffix acronyms

1 participant