Skip to content

KeyError when precinct isn't listed under <precincts> #37

@Kirkman

Description

@Kirkman

Last night ran into an issue with a LiveVoterTurnout XML file that Clarify wouldn't parse.

Basically, each Contest had a Intrastate New Resident precinct listed. But the master Precincts list didn't include it.

This led to a KeyError:

Traceback (most recent call last):
  File "parserClarity.py", line 294, in <module>
    p.parse( results_file )
  File "/Users/kirkman/.virtualenvs/elections3/lib/python3.7/site-packages/clarify/parser.py", line 51, in parse
    self._contests = self._parse_contests(tree)
  File "/Users/kirkman/.virtualenvs/elections3/lib/python3.7/site-packages/clarify/parser.py", line 284, in _parse_contests
    return [self._parse_contest(el) for el in contest_els]
  File "/Users/kirkman/.virtualenvs/elections3/lib/python3.7/site-packages/clarify/parser.py", line 284, in <listcomp>
    return [self._parse_contest(el) for el in contest_els]
  File "/Users/kirkman/.virtualenvs/elections3/lib/python3.7/site-packages/clarify/parser.py", line 312, in _parse_contest
    for c in self._parse_choices(contest_el, contest):
  File "/Users/kirkman/.virtualenvs/elections3/lib/python3.7/site-packages/clarify/parser.py", line 370, in _parse_choices
    for c_el in contest_el.xpath('Choice')]
  File "/Users/kirkman/.virtualenvs/elections3/lib/python3.7/site-packages/clarify/parser.py", line 370, in <listcomp>
    for c_el in contest_el.xpath('Choice')]
  File "/Users/kirkman/.virtualenvs/elections3/lib/python3.7/site-packages/clarify/parser.py", line 409, in _parse_choice
    subjurisdiction = self.get_result_jurisdiction(subjurisdiction_el.attrib['name'])
  File "/Users/kirkman/.virtualenvs/elections3/lib/python3.7/site-packages/clarify/parser.py", line 219, in get_result_jurisdiction
    return self._result_jurisdiction_lookup[name]
KeyError: 'Intrastate New Resident'

I'm attaching the ZIP file for reference. If I get some time next week I may try to see if I can find a solution and submit a pull request, but wanted to let you know about it.

lincoln-county.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions