Skip to content

Commit e2c9043

Browse files
committed
v1.0.2, narrow fix to handle only nickname and last name (#78)
1 parent 0b10018 commit e2c9043

File tree

4 files changed

+65
-8
lines changed

4 files changed

+65
-8
lines changed

docs/release_log.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Release Log
22
===========
3+
* 1.0.2 - Oct 26, 2018
4+
- Fix handling of only nickname and last name (#78)
35
* 1.0.1 - August 30, 2018
46
- Fix overzealous regex for "Ph. D." (#43)
57
- Add `surnames` attribute as aggregate of middle and last names

nameparser/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = (1, 0, 1)
1+
VERSION = (1, 0, 2)
22
__version__ = '.'.join(map(str, VERSION))
33
__author__ = "Derek Gulbranson"
44
__author_email__ = 'derek73@gmail.com'

nameparser/parser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,9 @@ def parse_full_name(self):
503503
self.title_list.append(piece)
504504
continue
505505
if not self.first:
506+
if p_len == 1 and self.nickname:
507+
self.last_list.append(piece)
508+
continue
506509
self.first_list.append(piece)
507510
continue
508511
if self.are_suffixes(pieces[i+1:]) or \

tests.py

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def m(self, actual, expected, hn):
4646
self.assertEqual(actual, expected, "'%s' != '%s' for '%s'\n%r" % (
4747
actual,
4848
expected,
49-
hn.full_name,
49+
hn.original,
5050
hn
5151
))
5252
except UnicodeDecodeError:
@@ -1358,7 +1358,7 @@ def test_add_constant_with_explicit_encoding(self):
13581358
self.assertIn('béck', c.titles)
13591359

13601360

1361-
class HumanNameNicknameTestCase(HumanNameTestBase):
1361+
class NicknameTestCase(HumanNameTestBase):
13621362
# https://code.google.com/p/python-nameparser/issues/detail?id=33
13631363
def test_nickname_in_parenthesis(self):
13641364
hn = HumanName("Benjamin (Ben) Franklin")
@@ -1445,12 +1445,64 @@ def test_duplicate_parenthesis_are_removed_from_name(self):
14451445
self.m(hn.last, "Jones", hn)
14461446
self.m(hn.suffix, "Jr.", hn)
14471447

1448-
def test_parenthesis_and_quotes_together(self):
1449-
hn = HumanName("Jennifer 'Jen' Jones (Duff)")
1450-
self.m(hn.first, "Jennifer", hn)
1451-
self.m(hn.last, "Jones", hn)
1452-
self.m(hn.nickname, "Jen Duff", hn)
1448+
def test_nickname_and_last_name(self):
1449+
hn = HumanName('"Rick" Edmonds')
1450+
self.m(hn.first, "", hn)
1451+
self.m(hn.last, "Edmonds", hn)
1452+
self.m(hn.nickname, "Rick", hn)
14531453

1454+
@unittest.expectedFailure
1455+
def test_nickname_and_last_name_with_title(self):
1456+
hn = HumanName('Senator "Rick" Edmonds')
1457+
self.m(hn.title, "Senator", hn)
1458+
self.m(hn.first, "", hn)
1459+
self.m(hn.last, "Edmonds", hn)
1460+
self.m(hn.nickname, "Rick", hn)
1461+
1462+
1463+
1464+
# class MaidenNameTestCase(HumanNameTestBase):
1465+
#
1466+
# def test_parenthesis_and_quotes_together(self):
1467+
# hn = HumanName("Jennifer 'Jen' Jones (Duff)")
1468+
# self.m(hn.first, "Jennifer", hn)
1469+
# self.m(hn.last, "Jones", hn)
1470+
# self.m(hn.nickname, "Jen", hn)
1471+
# self.m(hn.maiden, "Duff", hn)
1472+
#
1473+
# def test_maiden_name_with_nee(self):
1474+
# # https://en.wiktionary.org/wiki/née
1475+
# hn = HumanName("Mary Toogood nee Johnson")
1476+
# self.m(hn.first, "Mary", hn)
1477+
# self.m(hn.last, "Toogood", hn)
1478+
# self.m(hn.maiden, "Johnson", hn)
1479+
#
1480+
# def test_maiden_name_with_accented_nee(self):
1481+
# # https://en.wiktionary.org/wiki/née
1482+
# hn = HumanName("Mary Toogood née Johnson")
1483+
# self.m(hn.first, "Mary", hn)
1484+
# self.m(hn.last, "Toogood", hn)
1485+
# self.m(hn.maiden, "Johnson", hn)
1486+
#
1487+
# def test_maiden_name_with_nee_and_comma(self):
1488+
# # https://en.wiktionary.org/wiki/née
1489+
# hn = HumanName("Mary Toogood, née Johnson")
1490+
# self.m(hn.first, "Mary", hn)
1491+
# self.m(hn.last, "Toogood", hn)
1492+
# self.m(hn.maiden, "Johnson", hn)
1493+
#
1494+
# def test_maiden_name_with_nee_with_parenthesis(self):
1495+
# hn = HumanName("Mary Toogood (nee Johnson)")
1496+
# self.m(hn.first, "Mary", hn)
1497+
# self.m(hn.last, "Toogood", hn)
1498+
# self.m(hn.maiden, "Johnson", hn)
1499+
#
1500+
# def test_maiden_name_with_parenthesis(self):
1501+
# hn = HumanName("Mary Toogood (Johnson)")
1502+
# self.m(hn.first, "Mary", hn)
1503+
# self.m(hn.last, "Toogood", hn)
1504+
# self.m(hn.maiden, "Johnson", hn)
1505+
#
14541506

14551507
class PrefixesTestCase(HumanNameTestBase):
14561508

0 commit comments

Comments
 (0)