Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Handle short hispanic ethinicity (#140)
Browse files Browse the repository at this point in the history
Add parsing support for short hispanic ethnicity like `H/M` for
instance.

Drive by:
* Add the same think for black

Fixes #111
  • Loading branch information
rgreinho committed Jun 9, 2019
1 parent ec52d24 commit 0a350da
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 7 additions & 3 deletions scrapd/core/apd.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,14 +496,18 @@ def parse_fleg(fleg):
d = {}
try:
d[Fields.GENDER] = fleg.pop().replace(',', '').lower()
if d.get(Fields.GENDER) == 'f':
if d.get(Fields.GENDER, '').lower() == 'f':
d[Fields.GENDER] = 'female'
elif d.get(Fields.GENDER) == 'm':
elif d.get(Fields.GENDER, '').lower() == 'm':
d[Fields.GENDER] = 'male'

d[Fields.ETHNICITY] = fleg.pop().replace(',', '')
if d.get(Fields.ETHNICITY) == 'W':
if d.get(Fields.ETHNICITY, '').lower() == 'w':
d[Fields.ETHNICITY] = 'White'
elif d.get(Fields.ETHNICITY, '').lower() == 'h':
d[Fields.ETHNICITY] = 'Hispanic'
elif d.get(Fields.ETHNICITY, '').lower() == 'b':
d[Fields.ETHNICITY] = 'Black'
except IndexError:
pass

Expand Down
19 changes: 18 additions & 1 deletion tests/core/test_apd.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,27 @@ def test_extract_traffic_fatalities_page_details_link_00(news_page):
Fields.AGE: 19,
},
),
(
'Ernesto Gonzales Garcia, H/M, (DOB: 11/15/1977) ',
{
Fields.FIRST_NAME: "Ernesto",
Fields.LAST_NAME: "Garcia",
Fields.ETHNICITY: "Hispanic",
Fields.GENDER: "male",
Fields.DOB: date(1977, 11, 15)
},
),
(
'B/F, DOB: 01-01-99',
{
Fields.ETHNICITY: "Black",
Fields.GENDER: "female",
Fields.DOB: date(1999, 1, 1)
},
),
))
def test_process_deceased_field_00(deceased, expected):
"""Ensure a deceased field is parsed correctly."""
d = {}
d = apd.process_deceased_field(deceased)
for key in expected:
assert d[key] == expected[key]
Expand Down

0 comments on commit 0a350da

Please sign in to comment.