Skip to content

Commit 8ab1c8d

Browse files
authored
Merge pull request #364 from seperman/dev
v6.2.3
2 parents 277ed77 + 1353b72 commit 8ab1c8d

17 files changed

+77
-39
lines changed

AUTHORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ Authors in order of the timeline of their contributions:
4848
- [dtorres-sf](https://github.com/dtorres-sf) for the fix for diffing using iterable_compare_func with nested objects.
4949
- [Enric Pou](https://github.com/epou) for bug fix of ValueError when using Decimal 0.x
5050
- [Uwe Fladrich](https://github.com/uwefladrich) for fixing bug when diff'ing non-sequence iterables
51+
- [Michal Ozery-Flato](https://github.com/michalozeryflato) for setting equal_nan=ignore_nan_inequality in the call for np.array_equal
52+
- [martin-kokos](https://github.com/martin-kokos) for using Pytest's tmp_path fixture instead of /tmp/

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# DeepDiff Change log
22

3+
- v6-2-3
4+
- Switching to Orjson for serialization to improve the performance.
5+
- Setting `equal_nan=ignore_nan_inequality` in the call for `np.array_equal`
6+
- Using Pytest's tmp_path fixture instead of `/tmp/`
37
- v6-2-2
48
- Enum test fix for python 3.11
59
- Adding support for dateutils rrules

MANIFEST.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ include pytest.ini
99
include *.py
1010
recursive-include docs/ *.rst
1111
recursive-include docs/ *.png
12-
recursive-include tests *.py
12+
recursive-include tests *.csv
1313
recursive-include tests *.json
14+
recursive-include tests *.pickle
15+
recursive-include tests *.py
16+
recursive-include tests *.toml
17+
recursive-include tests *.yaml
1418
global-exclude __pycache__
1519
global-exclude *.py[co]

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# DeepDiff v 6.2.2
1+
# DeepDiff v 6.2.3
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)
@@ -14,10 +14,12 @@
1414

1515
Tested on Python 3.7+ and PyPy3.
1616

17-
- **[Documentation](https://zepworks.com/deepdiff/6.2.2/)**
17+
- **[Documentation](https://zepworks.com/deepdiff/6.2.3/)**
1818

1919
## What is new?
2020

21+
Please check the [ChangeLog](CHANGELOG.md) file for the detailed information.
22+
2123
DeepDiff 6-2-0
2224

2325
- Major improvement in the diff report for lists when items are all hashable and the order of items is important.
@@ -69,13 +71,13 @@ Note: if you want to use DeepDiff via commandline, make sure to run `pip install
6971

7072
DeepDiff gets the difference of 2 objects.
7173

72-
> - Please take a look at the [DeepDiff docs](https://zepworks.com/deepdiff/6.2.2/diff.html)
73-
> - The full documentation of all modules can be found on <https://zepworks.com/deepdiff/6.2.2/>
74+
> - Please take a look at the [DeepDiff docs](https://zepworks.com/deepdiff/6.2.3/diff.html)
75+
> - The full documentation of all modules can be found on <https://zepworks.com/deepdiff/6.2.3/>
7476
> - Tutorials and posts about DeepDiff can be found on <https://zepworks.com/tags/deepdiff/>
7577
7678
## A few Examples
7779

78-
> Note: This is just a brief overview of what DeepDiff can do. Please visit <https://zepworks.com/deepdiff/6.2.2/> for full documentation.
80+
> Note: This is just a brief overview of what DeepDiff can do. Please visit <https://zepworks.com/deepdiff/6.2.3/> for full documentation.
7981
8082
### List difference ignoring order or duplicates
8183

@@ -279,8 +281,8 @@ Example:
279281
```
280282

281283

282-
> - Please take a look at the [DeepDiff docs](https://zepworks.com/deepdiff/6.2.2/diff.html)
283-
> - The full documentation can be found on <https://zepworks.com/deepdiff/6.2.2/>
284+
> - Please take a look at the [DeepDiff docs](https://zepworks.com/deepdiff/6.2.3/diff.html)
285+
> - The full documentation can be found on <https://zepworks.com/deepdiff/6.2.3/>
284286
285287

286288
# Deep Search
@@ -312,17 +314,17 @@ And you can pass all the same kwargs as DeepSearch to grep too:
312314
{'matched_paths': {"root['somewhere']": 'around'}, 'matched_values': {"root['long']": 'somewhere'}}
313315
```
314316

315-
> - Please take a look at the [DeepSearch docs](https://zepworks.com/deepdiff/6.2.2/dsearch.html)
316-
> - The full documentation can be found on <https://zepworks.com/deepdiff/6.2.2/>
317+
> - Please take a look at the [DeepSearch docs](https://zepworks.com/deepdiff/6.2.3/dsearch.html)
318+
> - The full documentation can be found on <https://zepworks.com/deepdiff/6.2.3/>
317319
318320
# Deep Hash
319321
(New in v4-0-0)
320322

321323
DeepHash is designed to give you hash of ANY python object based on its contents even if the object is not considered hashable!
322324
DeepHash is supposed to be deterministic in order to make sure 2 objects that contain the same data, produce the same hash.
323325

324-
> - Please take a look at the [DeepHash docs](https://zepworks.com/deepdiff/6.2.2/deephash.html)
325-
> - The full documentation can be found on <https://zepworks.com/deepdiff/6.2.2/>
326+
> - Please take a look at the [DeepHash docs](https://zepworks.com/deepdiff/6.2.3/deephash.html)
327+
> - The full documentation can be found on <https://zepworks.com/deepdiff/6.2.3/>
326328
327329
Let's say you have a dictionary object.
328330

@@ -370,8 +372,8 @@ Which you can write as:
370372
At first it might seem weird why DeepHash(obj)[obj] but remember that DeepHash(obj) is a dictionary of hashes of all other objects that obj contains too.
371373

372374

373-
> - Please take a look at the [DeepHash docs](https://zepworks.com/deepdiff/6.2.2/deephash.html)
374-
> - The full documentation can be found on <https://zepworks.com/deepdiff/6.2.2/>
375+
> - Please take a look at the [DeepHash docs](https://zepworks.com/deepdiff/6.2.3/deephash.html)
376+
> - The full documentation can be found on <https://zepworks.com/deepdiff/6.2.3/>
375377
376378

377379
# Using DeepDiff in unit tests
@@ -451,11 +453,11 @@ Thank you!
451453

452454
How to cite this library (APA style):
453455

454-
Dehpour, S. (2022). DeepDiff (Version 6.2.2) [Software]. Available from https://github.com/seperman/deepdiff.
456+
Dehpour, S. (2022). DeepDiff (Version 6.2.3) [Software]. Available from https://github.com/seperman/deepdiff.
455457

456458
How to cite this library (Chicago style):
457459

458-
Dehpour, Sep. 2022. DeepDiff (version 6.2.2).
460+
Dehpour, Sep. 2022. DeepDiff (version 6.2.3).
459461

460462
# Authors
461463

deepdiff/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""This module offers the DeepDiff, DeepSearch, grep, Delta and DeepHash classes."""
22
# flake8: noqa
3-
__version__ = '6.2.2'
3+
__version__ = '6.2.3'
44
import logging
55

66
if __name__ == '__main__':

deepdiff/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ def _diff_numpy_array(self, level, parents_ids=frozenset(), local_tree=None):
13661366
if not self.ignore_order_func(level):
13671367
# fast checks
13681368
if self.significant_digits is None:
1369-
if np.array_equal(level.t1, level.t2):
1369+
if np.array_equal(level.t1, level.t2, equal_nan=self.ignore_nan_inequality):
13701370
return # all good
13711371
else:
13721372
try:

deepdiff/serialization.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io
44
import os
55
import json
6+
import orjson
67
import uuid
78
import logging
89
import re # NOQA
@@ -181,7 +182,7 @@ def to_json(self, default_mapping=None, **kwargs):
181182
'{"type_changes": {"root": {"old_type": "A", "new_type": "B", "old_value": "obj A", "new_value": "obj B"}}}'
182183
"""
183184
dic = self.to_dict(view_override=TEXT_VIEW)
184-
return json.dumps(dic, default=json_convertor_default(default_mapping=default_mapping), **kwargs)
185+
return json_dumps(dic, default_mapping=default_mapping, **kwargs)
185186

186187
def to_dict(self, view_override=None):
187188
"""
@@ -410,7 +411,7 @@ def load_path_content(path, file_type=None):
410411
file_type = path.split('.')[-1]
411412
if file_type == 'json':
412413
with open(path, 'r') as the_file:
413-
content = json.load(the_file)
414+
content = json_loads(the_file.read())
414415
elif file_type in {'yaml', 'yml'}:
415416
if yaml is None: # pragma: no cover.
416417
raise ImportError('Pyyaml needs to be installed.') # pragma: no cover.
@@ -474,7 +475,8 @@ def save_content_to_path(content, path, file_type=None, keep_backup=True):
474475
def _save_content(content, path, file_type, keep_backup=True):
475476
if file_type == 'json':
476477
with open(path, 'w') as the_file:
477-
content = json.dump(content, the_file)
478+
content = json_dumps(content)
479+
the_file.write(content)
478480
elif file_type in {'yaml', 'yml'}:
479481
if yaml is None: # pragma: no cover.
480482
raise ImportError('Pyyaml needs to be installed.') # pragma: no cover.
@@ -504,8 +506,15 @@ def _save_content(content, path, file_type, keep_backup=True):
504506
return content
505507

506508

509+
def _serialize_decimal(value):
510+
if value.as_tuple().exponent == 0:
511+
return int(value)
512+
else:
513+
return float(value)
514+
515+
507516
JSON_CONVERTOR = {
508-
decimal.Decimal: float,
517+
decimal.Decimal: _serialize_decimal,
509518
ordered_set.OrderedSet: list,
510519
type: lambda x: x.__name__,
511520
bytes: lambda x: x.decode('utf-8'),
@@ -552,7 +561,10 @@ def json_dumps(item, default_mapping=None, **kwargs):
552561
but the output it makes is a byte object and Postgres couldn't directly use it without
553562
encoding to str. So I switched back to json.
554563
"""
555-
return json.dumps(item, default=json_convertor_default(default_mapping=default_mapping), **kwargs)
564+
return orjson.dumps(
565+
item,
566+
default=json_convertor_default(default_mapping=default_mapping),
567+
**kwargs).decode(encoding='utf-8')
556568

557569

558570
json_loads = partial(json.loads, cls=JSONDecoder)

docs/authors.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ Authors in order of the timeline of their contributions:
6161
- `Enric Pou <https://github.com/epou>`__ for bug fix of ValueError
6262
when using Decimal 0.x
6363
- `Uwe Fladrich <https://github.com/uwefladrich>`__ for fixing bug when diff'ing non-sequence iterables
64-
64+
- `Michal Ozery-Flato <https://github.com/michalozeryflato>`__ for
65+
setting equal_nan=ignore_nan_inequality in the call for
66+
np.array_equal
67+
- `martin-kokos <https://github.com/martin-kokos>`__ for using Pytest’s
68+
tmp_path fixture instead of /tmp/
6569

6670
.. _Sep Dehpour (Seperman): http://www.zepworks.com
6771
.. _Victor Hahn Castell: http://hahncastell.de

docs/changelog.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ Changelog
55

66
DeepDiff Changelog
77

8+
- v6-2-3
9+
10+
- Switching to Orjson for serialization to improve the performance.
11+
- Setting ``equal_nan=ignore_nan_inequality`` in the call for
12+
``np.array_equal``
13+
- Using Pytest’s tmp_path fixture instead of ``/tmp/``
14+
815
- v6-2-2
916

1017
- Enum test fix for python 3.11

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
# built documents.
6161
#
6262
# The short X.Y version.
63-
version = '6.2.2'
63+
version = '6.2.3'
6464
# The full version, including alpha/beta/rc tags.
65-
release = '6.2.2'
65+
release = '6.2.3'
6666

6767
load_dotenv(override=True)
6868
DOC_VERSION = os.environ.get('DOC_VERSION', version)

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
contain the root `toctree` directive.
55
66
7-
DeepDiff 6.2.2 documentation!
7+
DeepDiff 6.2.3 documentation!
88
=============================
99

1010
*****************

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
ordered-set>=4.0.2,<4.2.0
2+
orjson

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 6.2.2
2+
current_version = 6.2.3
33
commit = True
44
tag = True
55
tag_name = {new_version}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if os.environ.get('USER', '') == 'vagrant':
1111
del os.link
1212

13-
version = '6.2.2'
13+
version = '6.2.3'
1414

1515

1616
def get_reqs(filename):

tests/test_command.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def test_cli_cant_find_file(self):
4444
('t1.pickle', 't2.pickle', {}, 0),
4545
('t1.yaml', 't2.yaml', {}, 0),
4646
])
47-
def test_deeppatch_command(self, t1, t2, args, expected_exit_code):
48-
t1_copy_path = f'/tmp/{t1}'
47+
def test_deeppatch_command(self, t1, t2, args, expected_exit_code, tmp_path):
48+
t1_copy_path = os.path.join(tmp_path, t1)
4949
t1 = os.path.join(FIXTURES_DIR, t1)
5050
t2 = os.path.join(FIXTURES_DIR, t2)
5151
copyfile(t1, t1_copy_path)
@@ -54,7 +54,7 @@ def test_deeppatch_command(self, t1, t2, args, expected_exit_code):
5454
assert delta_pickled.exit_code == expected_exit_code
5555

5656
if expected_exit_code == 0:
57-
delta_path = '/tmp/delta.pickle'
57+
delta_path = os.path.join(tmp_path, 'delta.pickle')
5858
with open(delta_path, 'wb') as the_file:
5959
the_file.write(delta_pickled.stdout_bytes)
6060

tests/test_delta.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,35 @@ def test_multiple_delta(self):
8484

8585
assert t1 + delta1 + delta2 == t3
8686

87-
def test_delta_dump_and_read1(self):
87+
def test_delta_dump_and_read1(self, tmp_path):
8888
t1 = [1, 2]
8989
t2 = [1, 2, 3, 5]
9090
diff = DeepDiff(t1, t2)
91-
path = '/tmp/delta_test.delta'
91+
path = os.path.join(tmp_path, 'delta_test.delta')
9292
with open(path, 'wb') as the_file:
9393
Delta(diff).dump(the_file)
9494
delta = Delta(delta_path=path)
9595
os.remove(path)
9696
assert delta + t1 == t2
9797

98-
def test_delta_dump_and_read2(self):
98+
def test_delta_dump_and_read2(self, tmp_path):
9999
t1 = [1, 2]
100100
t2 = [1, 2, 3, 5]
101101
diff = DeepDiff(t1, t2)
102102
delta_content = Delta(diff).dumps()
103-
path = '/tmp/delta_test2.delta'
103+
path = os.path.join('tmp_path, delta_test2.delta')
104104
with open(path, 'wb') as the_file:
105105
the_file.write(delta_content)
106106
delta = Delta(delta_path=path)
107107
os.remove(path)
108108
assert delta + t1 == t2
109109

110-
def test_delta_dump_and_read3(self):
110+
def test_delta_dump_and_read3(self, tmp_path):
111111
t1 = [1, 2]
112112
t2 = [1, 2, 3, 5]
113113
diff = DeepDiff(t1, t2)
114114
delta_content = Delta(diff).dumps()
115-
path = '/tmp/delta_test2.delta'
115+
path = os.path.join('tmp_path, delta_test2.delta')
116116
with open(path, 'wb') as the_file:
117117
the_file.write(delta_content)
118118
with pytest.raises(ValueError) as excinfo:

tests/test_serialization.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ def test_pretty_form_method(self, expected, verbose_level):
318318
@pytest.mark.parametrize('test_num, value', [
319319
(1, {'10': None}),
320320
(2, {"type_changes": {"root": {"old_type": None, "new_type": list, "new_value": ["你好", 2, 3, 5]}}}),
321+
(3, {'10': Decimal(2017)}),
322+
(4, Decimal(2017.1)),
321323
])
322324
def test_json_dumps_and_loads(self, test_num, value):
323325
serialized = json_dumps(value)
324326
back = json_loads(serialized)
325-
assert value == back, f"test_json_dumps_and_loads tesst #{test_num} failed"
327+
assert value == back, f"test_json_dumps_and_loads test #{test_num} failed"

0 commit comments

Comments
 (0)