Deep diff#106
Open
adrien-berchet wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors dictionary comparison in dir_content_diff by switching from dictdiffer to deepdiff, improving the formatting of diff reports, and adding numeric tolerance support. It also updates docs/tests accordingly and refreshes development tooling configuration.
Changes:
- Replace
dictdiffer-based dict diffs withDeepDiffplus a custom numeric-tolerance operator, and update human-readable diff formatting. - Fix tree comparison behavior to avoid returning empty raw diff reports as “differences”, and add/adjust tests to cover new behaviors and output.
- Update dependencies, pre-commit hooks, docs intersphinx mapping, and gitignore entries.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
dir_content_diff/base_comparators.py |
Migrates dict comparison to DeepDiff, adds numeric tolerance operator, and refactors diff formatting/filtering. |
dir_content_diff/core.py |
Adjusts handling of file comparison results to avoid treating empty raw diffs as differences. |
pyproject.toml |
Swaps dictdiffer for deepdiff and adds a dev dependency group. |
docs/source/conf.py |
Updates intersphinx mapping to DeepDiff documentation. |
README.md |
Updates example output strings to match the new diff formatting. |
tests/test_base.py |
Updates and expands tests for DeepDiff output, tolerance semantics, NaN handling, and formatting behavior. |
tests/conftest.py |
Updates expected diff regex fixtures to match new report formatting. |
tests/test_parallel_execution.py |
Updates parallel execution tests to reflect removal of dictdiffer positional args usage. |
.pre-commit-config.yaml |
Bumps pre-commit hook versions for lint/format tooling. |
.gitignore |
Ignores worktrees directory. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+479
to
+496
| def diff(self, ref, comp, **kwargs): | ||
| """Compare 2 dictionaries. | ||
|
|
||
| This function calls :func:`dictdiffer.diff` to compare the dictionaries, read the doc of | ||
| this function for details on args and kwargs. | ||
| This function compares dictionaries and returns a machine-readable diff report. | ||
|
|
||
| Keyword Args: | ||
| tolerance (float): Relative threshold to consider when comparing two float numbers. | ||
| absolute_tolerance (float): Absolute threshold to consider when comparing | ||
| two float numbers. | ||
| ignore (set[list]): Set of keys that should not be checked. | ||
| path_limit (list[str]): List of path limit tuples or :class:`dictdiffer.utils.PathLimit` | ||
| object to limit the diff recursion depth. | ||
| **kwargs: Additional keyword arguments are passed to :class:`deepdiff.diff.DeepDiff`. | ||
| """ | ||
| errors = self.current_state.get("format_errors", []) | ||
| tolerance = kwargs.pop("tolerance", None) | ||
| absolute_tolerance = kwargs.pop("absolute_tolerance", None) | ||
| custom_operators = list(kwargs.pop("custom_operators", [])) | ||
| custom_operators.insert( | ||
| 0, _NumericToleranceOperator(tolerance, absolute_tolerance) | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces significant improvements to dictionary comparison functionality by replacing the
dictdifferdependency withdeepdiff, enhancing diff output formatting, and adding support for numeric tolerance in comparisons. It also updates development dependencies and pre-commit hooks to newer versions for better reliability and maintainability.Dictionary Comparison Refactor and Improvements:
dictdifferdependency withdeepdifffor dictionary comparisons, resulting in more robust and detailed diff reports (pyproject.toml,dir_content_diff/base_comparators.py). [1] [2] [3]_NumericToleranceOperator) to allow approximate equality for floats and numbers in dictionary diffs (dir_content_diff/base_comparators.py).dir_content_diff/base_comparators.py,README.md). [1] [2] [3]Pre-commit and Dependency Updates:
.pre-commit-config.yamlfor improved linting and formatting. [1] [2] [3][dependency-groups]section topyproject.tomlto define development dependencies.Documentation and Miscellaneous:
deepdiffdocumentation instead ofdictdiffer(docs/source/conf.py).dir_content_diff/core.pyto properly handle file comparison results (dir_content_diff/core.py).