Skip to content

Commit

Permalink
changes in comparable itemgetter due to code analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
arturponinski committed Feb 4, 2022
1 parent bf79ae4 commit ae69b45
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions petl/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ def comparable_itemgetter(*args):
getter = operator.itemgetter(*args)
getter_with_default = _itemgetter_with_default(*args)

def f(x):
def getter_with_fallback(x):
try:
return getter(x)
except (IndexError, KeyError):
return getter_with_default(x)
g = lambda x: Comparable(f(x))
g = lambda x: Comparable(getter_with_fallback(x))
return g


Expand Down
9 changes: 4 additions & 5 deletions petl/test/transform/test_sorts.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import pytest

import petl
from petl.compat import next


Expand Down Expand Up @@ -530,14 +529,14 @@ def test_sort_missing_cell_numeric():
tbl = (('a', 'b'), ('4',), ('2', '1'), ('1',))
expect = (('a', 'b'), ('1',), ('2', '1'), ('4',))

sorted = sort(tbl)
ieq(expect, sorted)
tbl_sorted = sort(tbl)
ieq(expect, tbl_sorted)


def test_sort_missing_cell_text():
""" Sorting table with missing values raises IndexError #385 """
tbl = (('a', 'b', 'c'), ('C',), ('A', '4', '5'))
expect = (('a', 'b', 'c'), ('A', '4', '5'), ('C',))

sorted = sort(tbl)
ieq(expect, sorted)
tbl_sorted = sort(tbl)
ieq(expect, tbl_sorted)

0 comments on commit ae69b45

Please sign in to comment.