Skip to content

Commit 7ad36b4

Browse files
authored
Merge pull request #188 from seperman/dev
5.0.0: Delta, Better Numpy support, Pretty view
2 parents af1a0d4 + f225d76 commit 7ad36b4

File tree

86 files changed

+9471
-2153
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+9471
-2153
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,9 @@ target/
6363
.idea/
6464
.~lock*
6565

66-
.python-version
66+
.python-version*
6767

68+
temp*
69+
70+
# env file
71+
.env

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ matrix:
1212
install:
1313
- pip install -r requirements-dev.txt
1414

15-
script: pytest --cov=deepdiff tests/
15+
script: pytest --cov=deepdiff tests/ --runslow
1616

1717
after_success:
1818
- coveralls

AUTHORS

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
Developer:
2+
13
- Seperman
2-
- Victor Hahn Castell @ Flexoptix
34

4-
And many thanks to the following people for their contributions to DeepDiff:
5+
And many thanks to the following people for their contributions to DeepDiff!
56

7+
- Victor Hahn Castell @ Flexoptix for tree view and major contributions.
68
- nfvs for Travis-CI setup script.
79
- brbsix for initial Py3 porting.
810
- WangFenjin for Unicode support.
@@ -26,3 +28,7 @@ And many thanks to the following people for their contributions to DeepDiff:
2628
- Hugo (hugovk) for fixes for Python 3.10 and dropping support for EOL Python 3.4
2729
- Andrey Gavrilin (gaal-dev) for hashing classes.
2830
- Ivan Piskunov (van-ess0) for deprecation warning enhancement.
31+
- Nathaniel Brown (nathanielobrown) Adds support for datetime.time
32+
- Michał Karaś (MKaras93) for the pretty view
33+
- Christian Kothe (chkothe) for the basic support for diffing numpy arrays
34+
- Timothy (timson) for truncate_datetime

CHANGELOG.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
DeepDiff Change log
2+
3+
- v5-0-0: Introducing the Delta object, Improving Numpy support, Fixing tuples comparison when ignore_order=True, Dramatically improving the results when ignore_order=True by running in passes, Introducing pretty print view, deep_distance, purge, progress logging, cache and truncate_datetime.
4+
- v4-3-3: Adds support for datetime.time
5+
- v4-3-2: Deprecation Warning Enhancement
6+
- v4-3-1: Fixing the issue with exclude_path and hash calculations when dictionaries were inside iterables. https://github.com/seperman/deepdiff/issues/174
7+
- v4-3-0: adding exclude_obj_callback
8+
- v4-2-0: .json property is finally removed. Fix for Py3.10. Dropping support for EOL Python 3.4. Ignoring private keys when calculating hashes. For example __init__ is not a part of hash calculation anymore. Fix for #166 Problem with comparing lists, with an boolean as element.
9+
- v4-0-9: Fixing the bug for hashing custom unhashable objects
10+
- v4-0-8: Adding ignore_nan_inequality for float('nan')
11+
- v4-0-7: Hashing of the number 1 vs. True
12+
- v4-0-6: found a tiny bug in Python formatting of numbers in scientific notation. Added a workaround.
13+
- v4-0-5: Fixing number diffing. Adding number_format_notation and number_to_string_func.
14+
- v4-0-4: Adding ignore_string_case and ignore_type_subclasses
15+
- v4-0-3: Adding versionbump tool for release
16+
- v4-0-2: Fixing installation issue where rst files are missing.
17+
- v4-0-1: Fixing installation Tarball missing requirements.txt . DeepDiff v4+ should not show up as pip installable for Py2. Making Murmur3 installation optional.
18+
- v4-0-0: Ending Python 2 support, Adding more functionalities and documentation for DeepHash. Switching to Pytest for testing. Switching to Murmur3 128bit for hashing. Fixing classes which inherit from classes with slots didn't have all of their slots compared. Renaming ContentHash to DeepHash. Adding exclude by path and regex path to DeepHash. Adding ignore_type_in_groups. Adding match_string to DeepSearch. Adding Timedelta object diffing.
19+
- v3-5-0: Exclude regex path
20+
- v3-3-0: Searching for objects and class attributes
21+
- v3-2-2: Adding help(deepdiff)
22+
- v3-2-1: Fixing hash of None
23+
- v3-2-0: Adding grep for search: object | grep(item)
24+
- v3-1-3: Unicode vs. Bytes default fix
25+
- v3-1-2: NotPresent Fix when item is added or removed.
26+
- v3-1-1: Bug fix when item value is None (#58)
27+
- v3-1-0: Serialization to/from json
28+
- v3-0-0: Introducing Tree View
29+
- v2-5-3: Bug fix on logging for content hash.
30+
- v2-5-2: Bug fixes on content hash.
31+
- v2-5-0: Adding ContentHash module to fix ignore_order once and for all.
32+
- v2-1-0: Adding Deep Search. Now you can search for item in an object.
33+
- v2-0-0: Exclusion patterns better coverage. Updating docs.
34+
- v1-8-0: Exclusion patterns.
35+
- v1-7-0: Deep Set comparison.
36+
- v1-6-0: Unifying key names. i.e newvalue is new_value now. For backward compatibility, newvalue still works.
37+
- v1-5-0: Fixing ignore order containers with unordered items. Adding significant digits when comparing decimals. Changes property is deprecated.
38+
- v1-1-0: Changing Set, Dictionary and Object Attribute Add/Removal to be reported as Set instead of List. Adding Pypy compatibility.
39+
- v1-0-2: Checking for ImmutableMapping type instead of dict
40+
- v1-0-1: Better ignore order support
41+
- v1-0-0: Restructuring output to make it more useful. This is NOT backward compatible.
42+
- v0-6-1: Fixiing iterables with unhashable when order is ignored
43+
- v0-6-0: Adding unicode support
44+
- v0-5-9: Adding decimal support
45+
- v0-5-8: Adding ignore order of unhashables support
46+
- v0-5-7: Adding ignore order support
47+
- v0-5-6: Adding slots support
48+
- v0-5-5: Adding loop detection

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 - 2016 Sep Ehr (Seperman) and contributors
3+
Copyright (c) 2014 - 2020 Sep Dehpour (Seperman) and contributors
44
www.zepworks.com
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include LICENSE
22
include AUTHORS
3+
include CHANGELOG
34
include *.rst
45
include deepdiff/*.rst
56
include *.txt

README.md

Lines changed: 14 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# DeepDiff v 4.3.2
1+
# DeepDiff v 5.0.0
22

33
<!-- ![Downloads](https://img.shields.io/pypi/dm/deepdiff.svg?style=flat) -->
44
![Python Versions](https://img.shields.io/pypi/pyversions/deepdiff.svg?style=flat)
@@ -47,6 +47,7 @@ DeepDiff gets the difference of 2 objects.
4747

4848
> - Please take a look at the [DeepDiff docs](deepdiff/diff_doc.rst)
4949
> - The full documentation can be found on <https://deepdiff.readthedocs.io>
50+
> - Tutorials can be found on <https://zepworks.com/tags/deepdiff/>
5051
5152
## A few Examples
5253

@@ -417,50 +418,7 @@ And then running
417418

418419
# ChangeLog
419420

420-
- v4-3-2: Deprecation Warning Enhancement
421-
- v4-3-1: Fixing the issue with exclude_path and hash calculations when dictionaries were inside iterables. https://github.com/seperman/deepdiff/issues/174
422-
- v4-3-0: adding exclude_obj_callback
423-
- v4-2-0: .json property is finally removed. Fix for Py3.10. Dropping support for EOL Python 3.4. Ignoring private keys when calculating hashes. For example __init__ is not a part of hash calculation anymore. Fix for #166 Problem with comparing lists, with an boolean as element.
424-
- v4-0-9: Fixing the bug for hashing custom unhashable objects
425-
- v4-0-8: Adding ignore_nan_inequality for float('nan')
426-
- v4-0-7: Hashing of the number 1 vs. True
427-
- v4-0-6: found a tiny bug in Python formatting of numbers in scientific notation. Added a workaround.
428-
- v4-0-5: Fixing number diffing. Adding number_format_notation and number_to_string_func.
429-
- v4-0-4: Adding ignore_string_case and ignore_type_subclasses
430-
- v4-0-3: Adding versionbump tool for release
431-
- v4-0-2: Fixing installation issue where rst files are missing.
432-
- v4-0-1: Fixing installation Tarball missing requirements.txt . DeepDiff v4+ should not show up as pip installable for Py2. Making Murmur3 installation optional.
433-
- v4-0-0: Ending Python 2 support, Adding more functionalities and documentation for DeepHash. Switching to Pytest for testing. Switching to Murmur3 128bit for hashing. Fixing classes which inherit from classes with slots didn't have all of their slots compared. Renaming ContentHash to DeepHash. Adding exclude by path and regex path to DeepHash. Adding ignore_type_in_groups. Adding match_string to DeepSearch. Adding Timedelta object diffing.
434-
- v3-5-0: Exclude regex path
435-
- v3-3-0: Searching for objects and class attributes
436-
- v3-2-2: Adding help(deepdiff)
437-
- v3-2-1: Fixing hash of None
438-
- v3-2-0: Adding grep for search: object | grep(item)
439-
- v3-1-3: Unicode vs. Bytes default fix
440-
- v3-1-2: NotPresent Fix when item is added or removed.
441-
- v3-1-1: Bug fix when item value is None (#58)
442-
- v3-1-0: Serialization to/from json
443-
- v3-0-0: Introducing Tree View
444-
- v2-5-3: Bug fix on logging for content hash.
445-
- v2-5-2: Bug fixes on content hash.
446-
- v2-5-0: Adding ContentHash module to fix ignore_order once and for all.
447-
- v2-1-0: Adding Deep Search. Now you can search for item in an object.
448-
- v2-0-0: Exclusion patterns better coverage. Updating docs.
449-
- v1-8-0: Exclusion patterns.
450-
- v1-7-0: Deep Set comparison.
451-
- v1-6-0: Unifying key names. i.e newvalue is new_value now. For backward compatibility, newvalue still works.
452-
- v1-5-0: Fixing ignore order containers with unordered items. Adding significant digits when comparing decimals. Changes property is deprecated.
453-
- v1-1-0: Changing Set, Dictionary and Object Attribute Add/Removal to be reported as Set instead of List. Adding Pypy compatibility.
454-
- v1-0-2: Checking for ImmutableMapping type instead of dict
455-
- v1-0-1: Better ignore order support
456-
- v1-0-0: Restructuring output to make it more useful. This is NOT backward compatible.
457-
- v0-6-1: Fixiing iterables with unhashable when order is ignored
458-
- v0-6-0: Adding unicode support
459-
- v0-5-9: Adding decimal support
460-
- v0-5-8: Adding ignore order of unhashables support
461-
- v0-5-7: Adding ignore order support
462-
- v0-5-6: Adding slots support
463-
- v0-5-5: Adding loop detection
421+
Please take a look at the [changelog](changelog.md) file.
464422

465423
# Releases
466424

@@ -475,21 +433,28 @@ git push && git push --tags
475433
# Contribute
476434

477435
1. Please make your PR against the dev branch
478-
2. Please make sure that your PR has tests. Since DeepDiff is used in many sensitive data driven projects, we maintain 100% test coverage on the code. There are occasiannly exceptions to that rule but that is rare.
436+
2. Please make sure that your PR has tests. Since DeepDiff is used in many sensitive data driven projects, we strive to maintain around 100% test coverage on the code.
437+
438+
Please run `pytest --cov=deepdiff` to see the coverage report.
439+
440+
Or to see a more user friendly version, please run: `pytest --cov=deepdiff --cov-report term-missing`.
479441

480442
Thank you!
481443

482444
# Authors
483445

446+
Developer:
447+
484448
- Seperman (Sep Dehpour)
485449
- [Github](https://github.com/seperman)
486450
- [Linkedin](http://www.linkedin.com/in/sepehr)
487451
- [ZepWorks](http://www.zepworks.com)
488452

489-
- Victor Hahn Castell for major contributions
453+
And many thanks to the following people for their contributions to DeepDiff!
454+
455+
- Victor Hahn Castell for the tree view and major contributions:
490456
- [hahncastell.de](http://hahncastell.de)
491457
- [flexoptix.net](http://www.flexoptix.net)
492-
493458
- nfvs for Travis-CI setup script.
494459
- brbsix for initial Py3 porting.
495460
- WangFenjin for unicode support.
@@ -512,3 +477,4 @@ Thank you!
512477
- Necrophagos for Hashing of the number 1 vs. True
513478
- gaal-dev for adding exclude_obj_callback
514479
- Ivan Piskunov (van-ess0) for deprecation warning enhancement.
480+
- Michał Karaś (MKaras93) for the pretty view

conftest.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,64 @@
11
import sys
22
import os
3+
import json
4+
import pytest
35

46
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'tests')))
7+
8+
FIXTURES_DIR = os.path.join(os.path.dirname(__file__), 'tests/fixtures/')
9+
10+
11+
def pytest_addoption(parser):
12+
parser.addoption(
13+
"--runslow", action="store_true", default=False, help="run slow tests"
14+
)
15+
16+
17+
def pytest_configure(config):
18+
config.addinivalue_line("markers", "slow: mark test as slow to run")
19+
20+
21+
def pytest_collection_modifyitems(config, items):
22+
if config.getoption("--runslow"):
23+
# --runslow given in cli: do not skip slow tests
24+
return
25+
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
26+
for item in items:
27+
if "slow" in item.keywords:
28+
item.add_marker(skip_slow)
29+
30+
31+
@pytest.fixture(scope='class')
32+
def nested_a_t1():
33+
with open(os.path.join(FIXTURES_DIR, 'nested_a_t1.json')) as the_file:
34+
return json.load(the_file)
35+
36+
37+
@pytest.fixture(scope='class')
38+
def nested_a_t2():
39+
with open(os.path.join(FIXTURES_DIR, 'nested_a_t2.json')) as the_file:
40+
return json.load(the_file)
41+
42+
43+
@pytest.fixture(scope='class')
44+
def nested_a_result():
45+
with open(os.path.join(FIXTURES_DIR, 'nested_a_result.json')) as the_file:
46+
return json.load(the_file)
47+
48+
49+
@pytest.fixture(scope='class')
50+
def nested_b_t1():
51+
with open(os.path.join(FIXTURES_DIR, 'nested_b_t1.json')) as the_file:
52+
return json.load(the_file)
53+
54+
55+
@pytest.fixture(scope='class')
56+
def nested_b_t2():
57+
with open(os.path.join(FIXTURES_DIR, 'nested_b_t2.json')) as the_file:
58+
return json.load(the_file)
59+
60+
61+
@pytest.fixture(scope='class')
62+
def nested_b_result():
63+
with open(os.path.join(FIXTURES_DIR, 'nested_b_result.json')) as the_file:
64+
return json.load(the_file)

deepdiff/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
"""This module offers the DeepDiff, DeepSearch, grep and DeepHash classes."""
1+
"""This module offers the DeepDiff, DeepSearch, grep, Delta and DeepHash classes."""
22
# flake8: noqa
3-
__version__ = '4.3.2'
3+
__version__ = '5.0.0'
44
import logging
55

66
if __name__ == '__main__':
@@ -10,3 +10,5 @@
1010
from .diff import DeepDiff
1111
from .search import DeepSearch, grep
1212
from .deephash import DeepHash
13+
from .delta import Delta
14+
from .path import extract

deepdiff/anyset.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from ordered_set import OrderedSet
2+
from deepdiff.deephash import DeepHash
3+
from deepdiff.helper import dict_
4+
5+
6+
class AnySet:
7+
"""
8+
Any object can be in this set whether hashable or not.
9+
Note that the current implementation has memory leak and keeps
10+
traces of objects in itself even after popping.
11+
However one the AnySet object is deleted, all those traces will be gone too.
12+
"""
13+
def __init__(self, items=None):
14+
self._set = OrderedSet()
15+
self._hashes = dict_()
16+
self._hash_to_objects = dict_()
17+
if items:
18+
for item in items:
19+
self.add(item)
20+
21+
def add(self, item):
22+
try:
23+
self._set.add(item)
24+
except TypeError:
25+
hashes_obj = DeepHash(item, hashes=self._hashes)
26+
hash_ = hashes_obj[item]
27+
if hash_ not in self._hash_to_objects:
28+
self._hash_to_objects[hash_] = item
29+
30+
def __contains__(self, item):
31+
try:
32+
result = item in self._set
33+
except TypeError:
34+
hashes_obj = DeepHash(item, hashes=self._hashes)
35+
hash_ = hashes_obj[item]
36+
result = hash_ in self._hash_to_objects
37+
return result
38+
39+
def pop(self):
40+
if self._set:
41+
return self._set.pop()
42+
else:
43+
return self._hash_to_objects.pop(next(iter(self._hash_to_objects)))
44+
45+
def __eq__(self, other):
46+
set_part, hashes_to_objs_part = other
47+
return (self._set == set_part and self._hash_to_objects == hashes_to_objs_part)
48+
49+
__req__ = __eq__
50+
51+
def __repr__(self):
52+
return "< AnySet {}, {} >".format(self._set, self._hash_to_objects)
53+
54+
__str__ = __repr__
55+
56+
def __len__(self):
57+
return len(self._set) + len(self._hash_to_objects)
58+
59+
def __iter__(self):
60+
for item in self._set:
61+
yield item
62+
for item in self._hash_to_objects.values():
63+
yield item
64+
65+
def __bool__(self):
66+
return bool(self._set or self._hash_to_objects)

0 commit comments

Comments
 (0)