Skip to content

8.1.0 #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
Dec 16, 2024
Merged

8.1.0 #483

Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
cc30a3c
Fix _dict_from_slots, solves Path comparison
artemisart Sep 3, 2024
c1161b3
use hasattr instead of getattr None
artemisart Sep 3, 2024
47d7816
Removing deprecated attributes from setup.py
seperman Sep 11, 2024
38ac719
no diff anymore
artemisart Sep 12, 2024
ce1c8fb
add author
artemisart Sep 12, 2024
a114ed2
Merge pull request #480 from artemisart/patch-1
seperman Sep 12, 2024
5797841
relax orderly-set dependency
dimbleby Sep 15, 2024
ae50b1c
Merge branch 'dev' into relax-requirement
seperman Sep 29, 2024
111a2eb
Merge pull request #486 from dimbleby/relax-requirement
seperman Sep 29, 2024
5f22bd2
Add print() option
AaronDMarasco Oct 10, 2024
cdc4b30
Merge pull request #492 from AaronDMarasco/dev
seperman Oct 13, 2024
32df472
DeepHash: check numpy booleans like native booleans
doronbehar Oct 19, 2024
cee3d41
TestDeepHash: test numpy booleans
doronbehar Oct 20, 2024
5d30b3a
Merge pull request #496 from doronbehar/fix-np.bool_
seperman Oct 25, 2024
7bb48a1
Added missing suffix of tests/test_diff_include_paths_root.py
Oct 26, 2024
916f02f
Added tests for wrong diff result with include_paths and changed number
Oct 26, 2024
fc8baaa
Fixed include_paths fault, if only certain keys of a path are included
Oct 26, 2024
32d60a9
Merge pull request #499 from jlaba/master
seperman Nov 14, 2024
2d61bb1
updating dev dependencies. Adding tests for include_paths
seperman Nov 14, 2024
269a971
Merge branch 'dev' of github.com:seperman/deepdiff into dev
seperman Nov 14, 2024
f6c7bcb
Only lower if clean_key is instance of str
vmatt Nov 18, 2024
360c2f2
Add empty py.typed
Nov 18, 2024
d1c8f90
adding 2 more tests
seperman Dec 6, 2024
fe9fa86
adding python 3.13
seperman Dec 6, 2024
31d7275
Update CHANGELOG.md
seperman Dec 6, 2024
6d819f0
fixing the tests for old pythons
seperman Dec 6, 2024
2f290fe
upgrading dependencies
seperman Dec 6, 2024
151dbdd
only limit to 3.12 to check faster for the issue
seperman Dec 6, 2024
d7e2a94
somehow git actions didn't work. reverting.
seperman Dec 6, 2024
f86033f
Merge pull request #507 from Jorgen-VikingGod/add-py-typed
seperman Dec 6, 2024
85adbd2
add tests for group_by None cases
Dec 7, 2024
324aad3
Fixes __len__ of TreeResult when only comparing un-nested types
sherjeelshabih Dec 9, 2024
514e025
Merge pull request #504 from vmatt/patch-1
seperman Dec 14, 2024
743c901
Merge pull request #510 from sherjeelshabih/dev
seperman Dec 14, 2024
051c6d8
better support for Pydantic models. Ignore model_fields_set when
seperman Dec 14, 2024
767c96c
Merge branch 'dev' of github.com:seperman/deepdiff into dev
seperman Dec 14, 2024
5120230
slight optimization of TreeResult len
seperman Dec 14, 2024
f1d87e9
fixes #509
seperman Dec 15, 2024
42fd42d
fixes to_json() method chokes on some standard json.dumps() such as
seperman Dec 15, 2024
c464e04
fixes accessing the affected_root_keys property on the diff object re…
seperman Dec 15, 2024
737bb5a
updating docs
seperman Dec 16, 2024
d2d3806
fixing types to be compatible for python 3.8
seperman Dec 16, 2024
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
2 changes: 2 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ Authors in order of the timeline of their contributions:
- [sf-tcalhoun](https://github.com/sf-tcalhoun) for fixing "Instantiating a Delta with a flat_dict_list unexpectedly mutates the flat_dict_list"
- [dtorres-sf](https://github.com/dtorres-sf) for fixing iterable moved items when iterable_compare_func is used.
- [Florian Finkernagel](https://github.com/TyberiusPrime) for pandas and polars support.
- Mathis Chenuet [artemisart](https://github.com/artemisart) for fixing slots classes comparison.
- [Aaron D. Marasco](https://github.com/AaronDMarasco) added `prefix` option to `pretty()`
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

- v8-0-1
- Bugfix. Numpy should be optional.
- Added `prefix` option to `pretty()`

- v8-0-0

Expand Down
7 changes: 6 additions & 1 deletion deepdiff/deephash.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import polars
except ImportError:
polars = False
try:
import numpy as np
booleanTypes = (bool, np.bool_)
except ImportError:
booleanTypes = bool

Check warning on line 31 in deepdiff/deephash.py

View check run for this annotation

Codecov / codecov/patch

deepdiff/deephash.py#L30-L31

Added lines #L30 - L31 were not covered by tests

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -492,7 +497,7 @@
"""The main hash method"""
counts = 1

if isinstance(obj, bool):
if isinstance(obj, booleanTypes):
obj = self._prep_bool(obj)
result = None
elif self.use_enum_value and isinstance(obj, Enum):
Expand Down
2 changes: 1 addition & 1 deletion deepdiff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def unmangle(attribute):
else:
all_slots.extend(slots)

return {i: getattr(object, unmangle(i)) for i in all_slots}
return {i: getattr(object, key) for i in all_slots if hasattr(object, key := unmangle(i))}

def _diff_enum(self, level, parents_ids=frozenset(), local_tree=None):
t1 = detailed__dict__(level.t1, include_keys=ENUM_INCLUDE_KEYS)
Expand Down
8 changes: 6 additions & 2 deletions deepdiff/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _to_delta_dict(self, directed=True, report_repetition_required=True, always_

return deepcopy(dict(result))

def pretty(self):
def pretty(self, prefix=None):
"""
The pretty human readable string output for the diff object
regardless of what view was used to generate the diff.
Expand All @@ -310,12 +310,16 @@ def pretty(self):
Item root[1] removed from set.
"""
result = []
if prefix is None:
prefix = ''
keys = sorted(self.tree.keys()) # sorting keys to guarantee constant order across python versions.
for key in keys:
for item_key in self.tree[key]:
result += [pretty_print_diff(item_key)]

return '\n'.join(result)
if callable(prefix):
return "\n".join(f"{prefix(diff=self)}{r}" for r in result)
return "\n".join(f"{prefix}{r}" for r in result)


class _RestrictedUnpickler(pickle.Unpickler):
Expand Down
23 changes: 23 additions & 0 deletions docs/view.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,29 @@ Use the pretty method for human readable output. This is regardless of what view
Item root[4] removed from set.
Item root[1] removed from set.

The pretty method has an optional parameter ``prefix`` that allows a prefix string before every output line (*e.g.* for logging):
>>> from deepdiff import DeepDiff
>>> t1={1,2,4}
>>> t2={2,3}
>>> print(DeepDiff(t1, t2).pretty(prefix='Diff: '))
Diff: Item root[3] added to set.
Diff: Item root[4] removed from set.
Diff: Item root[1] removed from set.

The ``prefix`` may also be a callable function. This function must accept ``**kwargs``; as of this version, the only parameter is ``diff`` but the signature allows for future expansion.
The ``diff`` given will be the ``DeepDiff`` that ``pretty`` was called on; this allows interesting capabilities such as:
>>> from deepdiff import DeepDiff
>>> t1={1,2,4}
>>> t2={2,3}
>>> def callback(**kwargs):
... """Helper function using a hidden variable on the diff that tracks which count prints next"""
... kwargs['diff']._diff_count = 1 + getattr(kwargs['diff'], '_diff_count', 0)
... return f"Diff #{kwargs['diff']._diff_count}: "
...
>>> print(DeepDiff(t1, t2).pretty(prefix=callback))
Diff #1: Item root[3] added to set.
Diff #2: Item root[4] removed from set.
Diff #3: Item root[1] removed from set.


Text view vs. Tree view vs. vs. pretty() method
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
orderly-set==5.2.2
orderly-set>=5.2.3,<6
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def get_reqs(filename):
license='MIT',
packages=['deepdiff'],
zip_safe=True,
test_suite="tests",
include_package_data=True,
tests_require=['mock'],
long_description=long_description,
long_description_content_type='text/markdown',
install_requires=reqs,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_diff_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ def __str__(self):
t2 = Bad()

ddiff = DeepDiff(t1, t2)
result = {'unprocessed': ['root: Bad Object and Bad Object']}
result = {}
assert result == ddiff

def test_dict_none_item_removed(self):
Expand Down
6 changes: 6 additions & 0 deletions tests/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ def test_re(self):
a_hash = DeepHash(a)[a]
assert not( a_hash is unprocessed)

# https://github.com/seperman/deepdiff/issues/494
def test_numpy_bool(self):
a = {'b': np.array([True], dtype='bool')}
a_hash = DeepHash(a)[a]
assert not( a_hash is unprocessed)

class TestDeepHashPrep:
"""DeepHashPrep Tests covering object serialization."""

Expand Down
43 changes: 43 additions & 0 deletions tests/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,49 @@ def test_pretty_form_method(self, expected, verbose_level):
result = ddiff.pretty()
assert result == expected

@pytest.mark.parametrize("expected, verbose_level",
(
('\t\tItem root[5] added to dictionary.'
'\n\t\tItem root[3] removed from dictionary.'
'\n\t\tType of root[2] changed from int to str and value changed from 2 to "b".'
'\n\t\tValue of root[4] changed from 4 to 5.', 0),
('\t\tItem root[5] (5) added to dictionary.'
'\n\t\tItem root[3] (3) removed from dictionary.'
'\n\t\tType of root[2] changed from int to str and value changed from 2 to "b".'
'\n\t\tValue of root[4] changed from 4 to 5.', 2),
), ids=("verbose=0", "verbose=2")
)
def test_pretty_form_method_prefixed_simple(self, expected, verbose_level):
t1 = {2: 2, 3: 3, 4: 4}
t2 = {2: 'b', 4: 5, 5: 5}
ddiff = DeepDiff(t1, t2, verbose_level=verbose_level)
result = ddiff.pretty(prefix="\t\t")
assert result == expected

@pytest.mark.parametrize("expected, verbose_level",
(
('Diff #1: Item root[5] added to dictionary.'
'\nDiff #2: Item root[3] removed from dictionary.'
'\nDiff #3: Type of root[2] changed from int to str and value changed from 2 to "b".'
'\nDiff #4: Value of root[4] changed from 4 to 5.', 0),
('Diff #1: Item root[5] (5) added to dictionary.'
'\nDiff #2: Item root[3] (3) removed from dictionary.'
'\nDiff #3: Type of root[2] changed from int to str and value changed from 2 to "b".'
'\nDiff #4: Value of root[4] changed from 4 to 5.', 2),
), ids=("verbose=0", "verbose=2")
)
def test_pretty_form_method_prefixed_callback(self, expected, verbose_level):
def prefix_callback(**kwargs):
"""Helper function using a hidden variable on the diff that tracks which count prints next"""
kwargs['diff']._diff_count = 1 + getattr(kwargs['diff'], '_diff_count', 0)
return f"Diff #{kwargs['diff']._diff_count}: "

t1 = {2: 2, 3: 3, 4: 4}
t2 = {2: 'b', 4: 5, 5: 5}
ddiff = DeepDiff(t1, t2, verbose_level=verbose_level)
result = ddiff.pretty(prefix=prefix_callback)
assert result == expected

@pytest.mark.parametrize('test_num, value, func_to_convert_back', [
(1, {'10': None}, None),
(2, {"type_changes": {"root": {"old_type": None, "new_type": list, "new_value": ["你好", 2, 3, 5]}}}, None),
Expand Down
Loading