Skip to content

Conversation

eggachecat
Copy link
Contributor

@eggachecat eggachecat commented Jun 16, 2021

Add ignore_order_func to make ignore-order operation dynamic with level

  • I think it is an useful feature since it happens a lot when some of the fields concerns about order while some does not.

Allow custom operators to do/report some custom operations

  • Allow user to use custom operators to record some info with/without early stopping.
  • User just need to implement a class which contans two method:
    • match(level: DiffLevel) -> boolean to determine whether current operator should be applied on current level
    • diff(level: DiffLevel, instance: DeepDiff) -> boolean
      • to do custom diff logic with full access to DeepDiff instance
        • you can use instance.custom_report_result to record info
      • to return a boolean value to determine whether the process should quit or continue with default behavior

seperman and others added 7 commits April 28, 2021 23:20
Minor cleanup to documentation wording regarding iterable_compare_func
Add ignore_order_func to make ignore-order operation dynamic with level
allow custom operators to do/report some custom operations
allow
@eggachecat
Copy link
Contributor Author

hi @seperman would you like to do a CR for there two features?~

@eggachecat eggachecat changed the title Two features Two features: allowing custom operators and dynaimc ignoring order Jun 16, 2021
@seperman seperman changed the base branch from master to dev June 21, 2021 12:10
Copy link
Owner

@seperman seperman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @eggachecat
Thanks for this PR. These are great new features! 👍
I had a couple of minor comments. Please take a look at my comments when you have a chance.

Also do you mind adding the documentation for the 2 features if you have time? It will be more authentic if the docs are written by you. If I write the docs, it will be my own interpretation of what these features mean. Looking at the code seems like you actually had a use case for these features.

The ignore_order_func docs can go to ignore_order.rst and the custom_operators docs can go to other.rst.

deepdiff/diff.py Outdated
Comment on lines 164 to 170
# compatibility
if "ignore_order_func" not in _parameters:
_parameters["ignore_order_func"] = lambda *_args, **_kwargs: _parameters["ignore_order_func"]

if "custom_operators" not in _parameters:
_parameters["custom_operators"] = []

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need these for the compatibility. The _parameters is a self.__dict__ copy that is passed. If you remove these lines, the only test that fails is one delta test since it has _parameters hard-coded. Pleased update that test instead: https://github.com/seperman/deepdiff/blob/master/tests/test_delta.py#L1055

deepdiff/diff.py Outdated
self.ignore_order = ignore_order

if ignore_order_func is not None:
self.ignore_order_func = ignore_order_func
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the same simple line like the one for the custom_operators: self.ignore_order_func = ignore_order_func or lambda *_args, **_kwargs: ignore_order

deepdiff/diff.py Outdated

if not self._skip_this(level):
level.report_type = report_type
level.additional[CUSTOM_FILED] = extra_info
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: CUSTOM_FIELD

iterable_compare_func:
:ref:`iterable_compare_func_label`:
There are times that we want to guide DeepDiff as to what items to compare with other items. In such cases we can pass a iterable_compare_func that takes a function pointer to compare two items. It function takes two parameters and should return True if it is a match, False if it is not a match or raise CannotCompare if it is unable to compare the two.
There are times that we want to guide DeepDiff as to what items to compare with other items. In such cases we can pass a iterable_compare_func that takes a function pointer to compare two items. The function takes three parameters (x, y, level) and should return True if it is a match, False if it is not a match or raise CannotCompare if it is unable to compare the two.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. I thought I had found all the instances of this incorrect sentence already but obviously not!

@@ -0,0 +1,141 @@
import math
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the thorough tests!

path = change.path(force=FORCE_DEFAULT)
self['repetition_change'][path] = RemapDict(change.additional[
'repetition'])
'repetition'])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is giving pep8 error E126.

@eggachecat
Copy link
Contributor Author

okay! I will make fix these soon

@eggachecat
Copy link
Contributor Author

@seperman just updated the PR~
Would you like to do a CR ~

@codecov-commenter
Copy link

Codecov Report

Merging #252 (7e778fd) into dev (4ae6170) will decrease coverage by 0.01%.
The diff coverage is 99.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev     #252      +/-   ##
==========================================
- Coverage   99.63%   99.62%   -0.02%     
==========================================
  Files          13       14       +1     
  Lines        2768     2900     +132     
==========================================
+ Hits         2758     2889     +131     
- Misses         10       11       +1     
Impacted Files Coverage Δ
deepdiff/operator.py 90.90% <90.90%> (ø)
deepdiff/delta.py 100.00% <100.00%> (ø)
deepdiff/diff.py 100.00% <100.00%> (ø)
deepdiff/distance.py 100.00% <100.00%> (ø)
deepdiff/helper.py 100.00% <100.00%> (ø)
deepdiff/model.py 100.00% <100.00%> (ø)
deepdiff/search.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ae6170...7e778fd. Read the comment docs.

@seperman seperman merged commit a127ebd into seperman:dev Jul 2, 2021
@seperman
Copy link
Owner

seperman commented Jul 2, 2021

Hi @eggachecat
Thanks again for the great PR. I will keep you posted once the new DeepDiff with your changes is released.

@seperman
Copy link
Owner

Hi @eggachecat
DeepDiff 5.6.0 is released and it includes your PR.
Thank you for your great contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants