From a4183a571ced09b1a403656c54cecc9f8c5af783 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Tue, 30 Jul 2019 09:51:15 -0700 Subject: [PATCH 1/6] updating orderedset version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 23df8ce4..b075ccd0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ jsonpickle==1.0 -ordered-set==3.1 +ordered-set==3.1.1 From 263f2ab9c036f01dce9e8693a66d7ddba0f9115e Mon Sep 17 00:00:00 2001 From: John Vandenberg Date: Thu, 1 Aug 2019 22:07:31 +0700 Subject: [PATCH 2/6] Add LICENSE and tests to sdist Closes https://github.com/seperman/deepdiff/issues/154 --- MANIFEST.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index e1eec727..6cfccd47 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,11 @@ +include LICENSE +include AUTHORS include *.rst include deepdiff/*.rst include *.txt +include *.sh +include pytest.ini +include *.py +recursive-include tests *.py global-exclude __pycache__ global-exclude *.py[co] From 11eec09c5f31eaa92c32598a0352563735aa5625 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Thu, 17 Oct 2019 23:08:27 -0700 Subject: [PATCH 3/6] adding - v4-0-8: Adding ignore_nan_inequality for float('nan') --- README.md | 1 + deepdiff/diff.py | 7 ++++++- docs/index.rst | 1 + tests/test_diff_text.py | 8 ++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1eb9bd20..35d9b65d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/deepdiff/diff.py b/deepdiff/diff.py index f412f893..b7b355fc 100755 --- a/deepdiff/diff.py +++ b/deepdiff/diff.py @@ -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, @@ -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( @@ -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 @@ -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) diff --git a/docs/index.rst b/docs/index.rst index 89e5bd92..d4e78eda 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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. diff --git a/tests/test_diff_text.py b/tests/test_diff_text.py index a9374033..e2b25ea4 100755 --- a/tests/test_diff_text.py +++ b/tests/test_diff_text.py @@ -1723,3 +1723,11 @@ 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}, []), + ]) + def test_ignore_nan_inequality(self, t1, t2, params, expected_result): + assert expected_result == list(DeepDiff(t1, t2, **params).keys()) From 7f267f9099c030528eb6a6cdbe6b951ba7df2261 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Thu, 17 Oct 2019 23:09:04 -0700 Subject: [PATCH 4/6] =?UTF-8?q?Bump=20version:=204.0.7=20=E2=86=92=204.0.8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- deepdiff/__init__.py | 2 +- docs/conf.py | 4 ++-- docs/index.rst | 2 +- setup.cfg | 2 +- setup.py | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 35d9b65d..9d918ac3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# DeepDiff v 4.0.7 +# DeepDiff v 4.0.8 ![Python Versions](https://img.shields.io/pypi/pyversions/deepdiff.svg?style=flat) diff --git a/deepdiff/__init__.py b/deepdiff/__init__.py index 00e4223d..8910fb9a 100644 --- a/deepdiff/__init__.py +++ b/deepdiff/__init__.py @@ -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__': diff --git a/docs/conf.py b/docs/conf.py index c4395784..5fbfdf8f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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. diff --git a/docs/index.rst b/docs/index.rst index d4e78eda..7d4b633a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -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.** diff --git a/setup.cfg b/setup.cfg index 52b5f92b..84d90157 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 4.0.7 +current_version = 4.0.8 commit = True tag = True tag_name = {new_version} diff --git a/setup.py b/setup.py index d8215786..b126425f 100755 --- a/setup.py +++ b/setup.py @@ -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): From abdb0df936ea5bf42f82f5955e59589d265eb97c Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Thu, 17 Oct 2019 23:13:10 -0700 Subject: [PATCH 5/6] ignore that nan --- deepdiff/diff_doc.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/deepdiff/diff_doc.rst b/deepdiff/diff_doc.rst index 7af6ff06..d05fcdd6 100644 --- a/deepdiff/diff_doc.rst +++ b/deepdiff/diff_doc.rst @@ -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. @@ -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. @@ -482,6 +487,15 @@ ignore_string_case {} +ignore_nan_inequality + Whether to ignore float('nan') inequality in Python. + + >>> 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** From 22072f9075f44b50d5a0cef15eb2727243f527b0 Mon Sep 17 00:00:00 2001 From: Sep Dehpour Date: Thu, 17 Oct 2019 23:29:02 -0700 Subject: [PATCH 6/6] ignore for pypy3 --- deepdiff/diff_doc.rst | 2 +- tests/test_diff_text.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/deepdiff/diff_doc.rst b/deepdiff/diff_doc.rst index d05fcdd6..4f093099 100644 --- a/deepdiff/diff_doc.rst +++ b/deepdiff/diff_doc.rst @@ -488,7 +488,7 @@ ignore_string_case ignore_nan_inequality - Whether to ignore float('nan') inequality in Python. + 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 diff --git a/tests/test_diff_text.py b/tests/test_diff_text.py index e2b25ea4..09a7af16 100755 --- a/tests/test_diff_text.py +++ b/tests/test_diff_text.py @@ -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) @@ -1729,5 +1730,6 @@ def test_bool_vs_number(self): (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())