Skip to content

Commit

Permalink
use OrderedDict instead of defaultdict
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbPy committed Aug 7, 2020
1 parent bf414dd commit cd3f858
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions beancount_import/source/generic_importer_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import os
from glob import glob
from collections import defaultdict
from collections import OrderedDict
import itertools
from typing import Hashable, List, Dict, Optional

Expand Down Expand Up @@ -57,20 +57,20 @@ def name(self) -> str:
def prepare(self, journal: 'JournalEditor', results: SourceResults) -> None:
results.add_account(self.account)

entries = defaultdict(list) #type: Dict[Hashable,List[Directive]]
entries = OrderedDict() #type: Dict[Hashable, List[Directive]]
for f in self.files:
f_entries = self.importer.extract(f, existing_entries=journal.entries)
# collect all entries in current statement, grouped by hash
hashed_entries = defaultdict(list)
hashed_entries = OrderedDict() #type: Dict[Hashable, Directive]
for entry in f_entries:
key_ = self._get_key_from_imported_entry(entry)
self._add_description(entry)
hashed_entries[key_].append(entry)
hashed_entries.setdefault(key_, []).append(entry)
# deduplicate across statements
for key_ in hashed_entries:
# skip the existing entries from other statements. add remaining
n = len(entries[key_])
entries[key_].extend(hashed_entries[key_][n:])
entries.setdefault(key_, []).extend(hashed_entries[key_][n:])

get_pending_and_invalid_entries(
raw_entries=list(itertools.chain.from_iterable(entries.values())),
Expand Down

0 comments on commit cd3f858

Please sign in to comment.