From 02e4487194a0a5cce2a81bc0553b2c473a9cc903 Mon Sep 17 00:00:00 2001 From: blais Date: Wed, 6 Oct 2021 12:19:04 -0400 Subject: [PATCH 1/2] Added Decimal to numeric_types by default. --- petl/compat.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/petl/compat.py b/petl/compat.py index 71c29018..9505ebb0 100644 --- a/petl/compat.py +++ b/petl/compat.py @@ -15,9 +15,10 @@ if PY2: from itertools import ifilter, ifilterfalse, imap, izip, izip_longest from string import maketrans + from decimal import Decimal string_types = basestring, integer_types = int, long - numeric_types = bool, int, long, float + numeric_types = bool, int, long, float, Decimal text_type = unicode binary_type = str from urllib2 import urlopen @@ -40,13 +41,14 @@ imap = map izip = zip xrange = range + from decimal import Decimal from itertools import filterfalse as ifilterfalse from itertools import zip_longest as izip_longest from functools import reduce maketrans = str.maketrans string_types = str, integer_types = int, - numeric_types = bool, int, float + numeric_types = bool, int, float, Decimal class_types = type, text_type = str binary_type = bytes From aa37203976ff74f328f54bd33d05fd2ba99376b0 Mon Sep 17 00:00:00 2001 From: blais Date: Wed, 6 Oct 2021 12:28:59 -0400 Subject: [PATCH 2/2] Modified test for numeric types. --- petl/test/test_comparison.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/petl/test/test_comparison.py b/petl/test/test_comparison.py index 94bf3637..cbf041d7 100644 --- a/petl/test/test_comparison.py +++ b/petl/test/test_comparison.py @@ -2,6 +2,7 @@ from datetime import datetime +from decimal import Decimal from petl.test.helpers import eq_ @@ -29,9 +30,9 @@ def test_comparable(): eq_(e, a) # mixed numeric - d = [3., 1, 2.5] + d = [3., 1, 2.5, Decimal('1.5')] a = sorted(d, key=Comparable) - e = [1, 2.5, 3.] + e = [1, Decimal('1.5'), 2.5, 3.] eq_(e, a) # mixed numeric and bool