Skip to content
Merged

Dev #162

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
include LICENSE
include AUTHORS
include *.rst
include deepdiff/*.rst
include *.txt
include LICENSE AUTHORS
include *.sh
include pytest.ini
include *.py
recursive-include tests *.py
global-exclude __pycache__
global-exclude *.py[co]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DeepDiff v 4.0.7
# DeepDiff v 4.0.8

<!-- ![Downloads](https://img.shields.io/pypi/dm/deepdiff.svg?style=flat) -->
![Python Versions](https://img.shields.io/pypi/pyversions/deepdiff.svg?style=flat)
Expand Down Expand Up @@ -417,6 +417,7 @@ And then running

# ChangeLog

- v4-0-8: Adding ignore_nan_inequality for float('nan')
- v4-0-7: Hashing of the number 1 vs. True
- v4-0-6: found a tiny bug in Python formatting of numbers in scientific notation. Added a workaround.
- v4-0-5: Fixing number diffing. Adding number_format_notation and number_to_string_func.
Expand Down
2 changes: 1 addition & 1 deletion deepdiff/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""This module offers the DeepDiff, DeepSearch, grep and DeepHash classes."""
# flake8: noqa
__version__ = '4.0.7'
__version__ = '4.0.8'
import logging

if __name__ == '__main__':
Expand Down
7 changes: 6 additions & 1 deletion deepdiff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self,
ignore_type_subclasses=False,
ignore_string_case=False,
number_to_string_func=None,
ignore_nan_inequality=False,
verbose_level=1,
view=TEXT_VIEW,
hasher=None,
Expand All @@ -69,7 +70,7 @@ def __init__(self,
"The valid parameters are ignore_order, report_repetition, significant_digits, "
"number_format_notation, exclude_paths, exclude_types, exclude_regex_paths, ignore_type_in_groups, "
"ignore_string_type_changes, ignore_numeric_type_changes, ignore_type_subclasses, "
"number_to_string_func, verbose_level, view, and hasher.") % ', '.join(kwargs.keys()))
"ignore_nan_inequality, number_to_string_func, verbose_level, view, and hasher.") % ', '.join(kwargs.keys()))

self.ignore_order = ignore_order
self.ignore_type_in_groups = self.get_ignore_types_in_groups(
Expand All @@ -88,6 +89,7 @@ def __init__(self,
self.type_check_func = type_is_subclass_of_type_group if ignore_type_subclasses else type_in_type_group
self.ignore_string_case = ignore_string_case
self.number_to_string = number_to_string_func or number_to_string
self.ignore_nan_inequality = ignore_nan_inequality
self.hashes = {}
self.hasher = hasher

Expand Down Expand Up @@ -613,6 +615,9 @@ def __diff(self, level, parents_ids=frozenset({})):
self.__diff_types(level)
return

if self.ignore_nan_inequality and isinstance(level.t1, float) and str(level.t1) == str(level.t2) == 'nan':
return

if isinstance(level.t1, strings):
self.__diff_str(level)

Expand Down
14 changes: 14 additions & 0 deletions deepdiff/diff_doc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ ignore_type_subclasses: Boolean, default = False
ignore_string_case: Boolean, default = False
Whether to be case-sensitive or not when comparing strings. By settings ignore_string_case=False, strings will be compared case-insensitively.

ignore_nan_inequality: Boolean, default = False
Whether to ignore float('nan') inequality in Python.


**Returns**

A DeepDiff object that has already calculated the difference of the 2 items.
Expand Down Expand Up @@ -473,6 +477,7 @@ ignore_type_subclasses
>>> DeepDiff(obj_a, obj_c, ignore_type_in_groups=[(ClassA, ClassB)], ignore_type_subclasses=True)
{'values_changed': {'root.x': {'new_value': 3, 'old_value': 1}}, 'attribute_removed': [root.y]}


ignore_string_case
Whether to be case-sensitive or not when comparing strings. By settings ignore_string_case=False, strings will be compared case-insensitively.

Expand All @@ -482,6 +487,15 @@ ignore_string_case
{}


ignore_nan_inequality
Whether to ignore float('nan') inequality in Python. Note that this is a cPython "feature". Some versions of Pypy3 for example have nan==nan.

>>> float('nan') == float('nan')
False
>>> DeepDiff(float('nan'), float('nan'))
{'values_changed': {'root': {'new_value': nan, 'old_value': nan}}}
>>> DeepDiff(float('nan'), float('nan'), ignore_nan_inequality=True)
{}

**Tree View**

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
# built documents.
#
# The short X.Y version.
version = '4.0.7'
version = '4.0.8'
# The full version, including alpha/beta/rc tags.
release = '4.0.7'
release = '4.0.8'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
contain the root `toctree` directive.


DeepDiff 4.0.7 documentation!
DeepDiff 4.0.8 documentation!
=============================

**DeepDiff: Deep Difference of dictionaries, iterables, strings and other objects. It will recursively look for all the changes.**
Expand Down Expand Up @@ -281,6 +281,7 @@ Indices and tables
Changelog
=========

- v4-0-8: Adding ignore_nan_inequality for float('nan')
- v4-0-7: Hashing of the number 1 vs. True
- v4-0-6: found a tiny bug in Python formatting of numbers in scientific notation. Added a workaround.
- v4-0-5: Fixing number diffing. Adding number_format_notation and number_to_string_func.
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jsonpickle==1.0
ordered-set==3.1
ordered-set==3.1.1
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.0.7
current_version = 4.0.8
commit = True
tag = True
tag_name = {new_version}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if os.environ.get('USER', '') == 'vagrant':
del os.link

version = '4.0.7'
version = '4.0.8'


def get_reqs(filename):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_diff_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from decimal import Decimal
from deepdiff import DeepDiff
from deepdiff.helper import number_to_string
from deepdiff.helper import pypy3
from tests import CustomClass

logging.disable(logging.CRITICAL)
Expand Down Expand Up @@ -1723,3 +1724,12 @@ def test_bool_vs_number(self):

ddiff = DeepDiff(t1, t2, ignore_order=True)
assert ddiff == {}

@pytest.mark.parametrize('t1, t2, params, expected_result', [
(float('nan'), float('nan'), {}, ['values_changed']),
(float('nan'), float('nan'), {'ignore_nan_inequality': True}, []),
([1, float('nan')], [1, float('nan')], {'ignore_nan_inequality': True}, []),
])
@pytest.mark.skipif(pypy3, reason="some versions of pypy3 have nan==nan")
def test_ignore_nan_inequality(self, t1, t2, params, expected_result):
assert expected_result == list(DeepDiff(t1, t2, **params).keys())