GeezerVison is showing github.com — Do not apply format to non numbers · benthomasson/deepdiff@71a54e3
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: deepdiff/helper.py +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -340,6 +340,8 @@ def number_to_string(number, significant_digits, number_format_notation="f"): |
340 | 340 | with localcontext() as ctx: |
341 | 341 | ctx.prec = len(tup.digits) + tup.exponent + significant_digits |
342 | 342 | number = number.quantize(Decimal('0.' + '0' * significant_digits)) |
| 343 | + elif not isinstance(number, numbers): |
| 344 | + return number |
343 | 345 | result = (using % significant_digits).format(number) |
344 | 346 | # Special case for 0: "-0.00" should compare equal to "0.00" |
345 | 347 | if set(result) <= ZERO_DECIMAL_CHARACTERS: |
|
Collapse file
Copy file name to clipboardExpand all lines: tests/test_diff_other.py +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,3 +80,15 @@ def test_path_cache(self): |
80 | 80 | path1 = diff['values_changed'][0].path() |
81 | 81 | path2 = diff['values_changed'][0].path() |
82 | 82 | assert 'root[0]' == path1 == path2 |
| 83 | + |
| 84 | + def test_bool_str(self): |
| 85 | + t1 = {'key1': True} |
| 86 | + t2 = {'key1': 'Yes'} |
| 87 | + diff = DeepDiff(t1, t2, ignore_type_in_groups=[(bool, str)], |
| 88 | + ignore_numeric_type_changes=True) |
| 89 | + expected = {'values_changed': |
| 90 | + {"root['key1']": |
| 91 | + {'new_value': 'Yes', 'old_value': True} |
| 92 | + } |
| 93 | + } |
| 94 | + assert diff == expected |