Skip to content

Commit e42699a

Browse files
committed
Fix #66 handling of names composed entirely of conjunctions
1 parent 6962b51 commit e42699a

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

docs/release_log.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Release Log
44
- Add Dr to suffixes (#62)
55
- Add the full set of Italian derivatives from "di" (#59)
66
- Add parameter to specify the encoding of strings added to constants, use 'UTF-8' as fallback (#67)
7+
- Fix handling of names composed entirely of conjunctions (#66)
78
* 0.5.3 - June 27, 2017
89
- Remove emojis from initial string by default with option to include emojis (#58)
910
* 0.5.2 - March 19, 2017

nameparser/parser.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0):
641641
642642
"""
643643
length = len(pieces) + additional_parts_count
644-
# don't join on conjuctions if there's only 2 parts
644+
# don't join on conjunctions if there's only 2 parts
645645
if length < 3:
646646
return pieces
647647

@@ -658,7 +658,7 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0):
658658
for i, val in enumerate(conj_index):
659659
try:
660660
if conj_index[i+1] == val+1:
661-
contiguous_conj_i += [val]
661+
contiguous_conj_i += [val]
662662
except IndexError:
663663
pass
664664

@@ -680,7 +680,11 @@ def join_on_conjunctions(self, pieces, additional_parts_count=0):
680680
for i in reversed(delete_i):
681681
# delete pieces in reverse order or the index changes on each delete
682682
del pieces[i]
683-
683+
684+
if len(pieces) == 1:
685+
# if there's only one piece left, nothing left to do
686+
return pieces
687+
684688
# refresh conjunction index locations
685689
conj_index = [i for i, piece in enumerate(pieces) if self.is_conjunction(piece)]
686690

tests.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,10 @@ def test_conjunction_in_an_address_with_a_first_name_title(self):
12441244
# if you want to be technical, Queen is in FIRST_NAME_TITLES
12451245
self.m(hn.first, "Elizabeth", hn)
12461246

1247+
def test_name_is_conjunctions(self):
1248+
hn = HumanName("e and e")
1249+
self.m(hn.first, "e and e", hn)
1250+
12471251

12481252
class ConstantsCustomization(HumanNameTestBase):
12491253

0 commit comments

Comments
 (0)