Skip to content

Commit

Permalink
Use None instead of nan when skipping dialects
Browse files Browse the repository at this point in the history
This fixes #5.
  • Loading branch information
GjjvdBurg committed Dec 23, 2019
1 parent 10d7ae4 commit b68ae8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
14 changes: 5 additions & 9 deletions clevercsv/consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ def consistency_scores(data, dialects, skip=True, logger=print):
for dialect in sorted(dialects):
P = pattern_score(data, dialect)
if P < Qmax and skip:
scores[dialect] = {
"pattern": P,
"type": float("nan"),
"Q": float("nan"),
}
scores[dialect] = {"pattern": P, "type": None, "Q": None}
logger("%15r:\tP = %15.6f\tskip." % (dialect, P))
continue
T = type_score(data, dialect)
Expand All @@ -87,10 +83,10 @@ def consistency_scores(data, dialects, skip=True, logger=print):


def get_best_set(scores):
H = set()
Qmax = max((score["Q"] for score in scores.values()))
H = set([d for d, score in scores.items() if score["Q"] == Qmax])
return H
Qscores = [score["Q"] for score in scores.values()]
Qscores = filter(lambda q: not q is None, Qscores)
Qmax = max(Qscores)
return set([d for d, score in scores.items() if score["Q"] == Qmax])


def break_ties(data, dialects):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_unit/test_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class ConsistencyTestCase(unittest.TestCase):
def test_get_best_set_1(self):
scores = {
SimpleDialect(",", None, None): {"Q": 1.0},
SimpleDialect(";", None, None): {"Q": float("nan")},
SimpleDialect(";", None, None): {"Q": None},
SimpleDialect("|", None, None): {"Q": 2.0},
}
H = get_best_set(scores)
self.assertEqual(H, set([SimpleDialect("|", None, None)]))

def test_get_best_set_2(self):
scores = {
SimpleDialect(";", None, None): {"Q": float("nan")},
SimpleDialect(";", None, None): {"Q": None},
SimpleDialect(",", None, None): {"Q": 1.0},
SimpleDialect("|", None, None): {"Q": 2.0},
}
Expand Down

0 comments on commit b68ae8e

Please sign in to comment.