Skip to content

Commit 60230b6

Browse files
committed
ignore order in group enhancement
1 parent 3141ceb commit 60230b6

File tree

9 files changed

+61
-27
lines changed

9 files changed

+61
-27
lines changed

README.md

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ Tested on Python 3.4, 3.5, 3.6, 3.7, Pypy3
2323

2424
### Install from PyPi:
2525

26-
`pip install deepdiff`
26+
`pip install deepdiff`
2727

2828
DeepDiff prefers to use Murmur3 for hashing. However you have to manually install Murmur3 by running:
2929

30-
`pip install mmh3`
30+
`pip install mmh3`
3131

3232
Otherwise DeepDiff will be using SHA256 for hashing which is a cryptographic hash and is considerably slower.
3333

@@ -157,8 +157,7 @@ Digits **after** the decimal point. Internally it uses "{:.Xf}".format(Your Numb
157157
'new_value': 3.0,
158158
'old_type': <class 'int'>,
159159
'old_value': 3}}}
160-
>>> ddiff = DeepDiff(t1, t2, ignore_type_in_groups=True)
161-
>>> pprint(ddiff, indent=2)
160+
>>> ddiff = DeepDiff(t1, t2, ignore_type_in_groups=[(int, float)])
162161
{}
163162
```
164163

@@ -408,9 +407,11 @@ On MacOS Mojave some user experience difficulty when installing Murmur3.
408407

409408
The problem can be solved by running:
410409

411-
`xcode-select --install`
410+
`xcode-select --install`
411+
412+
And then running
412413

413-
And then running `pip install mmh3`
414+
`pip install mmh3`
414415

415416
# ChangeLog
416417

@@ -448,6 +449,16 @@ And then running `pip install mmh3`
448449
- v0-5-6: Adding slots support
449450
- v0-5-5: Adding loop detection
450451

452+
# Releases
453+
454+
We use bump2version to bump and tag releases.
455+
456+
```bash
457+
git checkout master && git pull
458+
bump2version {patch|minor|major}
459+
git push && git push --tags
460+
```
461+
451462
# Contribute
452463

453464
1. Please make your PR against the dev branch

deepdiff/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""This module offers the DeepDiff, DeepSearch, grep and DeepHash classes."""
22
# flake8: noqa
3-
__version__ = '4.0.2'
43
import logging
4+
import pkg_resources
55

66
if __name__ == '__main__':
77
logging.basicConfig(format='%(asctime)s %(levelname)8s %(message)s')
88

9+
__version__ = pkg_resources.get_distribution("deepdiff").version
10+
911
from .diff import DeepDiff
1012
from .search import DeepSearch, grep
1113
from .deephash import DeepHash

deepdiff/base.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ def get_ignore_types_in_groups(self, ignore_type_in_groups,
2222
ignore_numeric_type_changes):
2323
if ignore_type_in_groups:
2424
if isinstance(ignore_type_in_groups[0], type):
25-
ignore_type_in_groups = [OrderedSet(ignore_type_in_groups)]
26-
else:
27-
ignore_type_in_groups = list(map(OrderedSet, ignore_type_in_groups))
25+
ignore_type_in_groups = [ignore_type_in_groups]
2826
else:
2927
ignore_type_in_groups = []
3028

29+
result = []
30+
for item_group in ignore_type_in_groups:
31+
new_item_group = OrderedSet()
32+
for item in item_group:
33+
item = type(item) if item is None or not isinstance(item, type) else item
34+
new_item_group.add(item)
35+
result.append(new_item_group)
36+
ignore_type_in_groups = result
37+
3138
if ignore_string_type_changes and self.strings not in ignore_type_in_groups:
3239
ignore_type_in_groups.append(OrderedSet(self.strings))
3340

deepdiff/diff.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(self,
5555
ignore_type_in_groups=None,
5656
ignore_string_type_changes=False,
5757
ignore_numeric_type_changes=False,
58+
ignore_type_subclasses=False,
5859
verbose_level=1,
5960
view=TEXT_VIEW,
6061
hasher=None,
@@ -64,8 +65,8 @@ def __init__(self,
6465
"The following parameter(s) are not valid: %s\n"
6566
"The valid parameters are ignore_order, report_repetition, significant_digits, "
6667
"exclude_paths, exclude_types, exclude_regex_paths, ignore_type_in_groups, "
67-
"ignore_string_type_changes, ignore_numeric_type_changes, verbose_level, view, "
68-
"and hasher.") % ', '.join(kwargs.keys()))
68+
"ignore_string_type_changes, ignore_numeric_type_changes, ignore_type_subclasses, "
69+
"verbose_level, view, and hasher.") % ', '.join(kwargs.keys()))
6970

7071
self.ignore_order = ignore_order
7172
self.ignore_type_in_groups = self.get_ignore_types_in_groups(
@@ -78,6 +79,7 @@ def __init__(self,
7879
self.exclude_types_tuple = tuple(exclude_types) if exclude_types else None # we need tuple for checking isinstance
7980
self.ignore_string_type_changes = ignore_string_type_changes
8081
self.ignore_numeric_type_changes = ignore_numeric_type_changes
82+
self.ignore_type_subclasses = ignore_type_subclasses
8183
self.hashes = {}
8284
self.hasher = hasher
8385

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --pdbcls=IPython.terminal.debugger:Pdb

requirements-dev.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
-r requirements.txt
2-
pytest==4.0.1
3-
pytest-cov==2.6.0
4-
numpy==1.15.4
2+
pytest-4.3.1
3+
pytest-cov==2.6.1
4+
numpy==1.16.2
55
mmh3==2.5.1
6+
ipdb==0.11
7+
bump2version==0.5.10

setup.cfg

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,14 @@ builtins = json
44
statistics = true
55
ignore = E202
66
exclude = ./data,./src,.svn,CVS,.bzr,.hg,.git,__pycache__
7+
8+
[bumpversion]
9+
current_version = 0.4.2
10+
commit = True
11+
tag = True
12+
tag_name = {new_version}
13+
14+
[bumpversion:file:setup.py]
15+
[bumpversion:file:README.md]
16+
[bumpversion:file:docs/index.rst]
17+
[bumpversion:file:docs/conf.py]

setup.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import re
32
import sys
43
from setuptools import setup
54

@@ -11,16 +10,7 @@
1110
if os.environ.get('USER', '') == 'vagrant':
1211
del os.link
1312

14-
15-
VERSIONFILE = "deepdiff/__init__.py"
16-
with open(VERSIONFILE, "r") as the_file:
17-
verstrline = the_file.read()
18-
VSRE = r"^__version__ = ['\"]([^'\"]*)['\"]"
19-
mo = re.search(VSRE, verstrline, re.M)
20-
if mo:
21-
verstr = mo.group(1)
22-
else:
23-
raise RuntimeError("Unable to find version string in %s." % (VERSIONFILE,))
13+
version = '0.4.2'
2414

2515

2616
def get_reqs(filename):
@@ -37,7 +27,7 @@ def get_reqs(filename):
3727

3828

3929
setup(name='deepdiff',
40-
version=verstr,
30+
version=version,
4131
description='Deep Difference and Search of any Python object/data.',
4232
url='https://github.com/seperman/deepdiff',
4333
download_url='https://github.com/seperman/deepdiff/tarball/master',

tests/test_diff_text.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,13 @@ def test_ignore_type_in_groups_numbers_and_strings_when_ignore_order(self):
13751375
result = {'iterable_item_added': {'root[2]': 3.3}, 'iterable_item_removed': {'root[2]': 3}}
13761376
assert result == ddiff
13771377

1378+
def test_ignore_type_in_groups_none_and_objects(self):
1379+
t1 = [1, 2, 3, 'a', None]
1380+
t2 = [1.0, 2.0, 3.3, b'a', 'hello']
1381+
ddiff = DeepDiff(t1, t2, ignore_type_in_groups=[(1, 1.0), (None, str, bytes)])
1382+
result = {'values_changed': {'root[2]': {'new_value': 3.3, 'old_value': 3}}}
1383+
assert result == ddiff
1384+
13781385
def test_ignore_string_type_changes_when_dict_keys_merge_is_not_deterministic(self):
13791386
t1 = {'a': 10, b'a': 20}
13801387
t2 = {'a': 11, b'a': 22}

0 commit comments

Comments
 (0)