Skip to content

Deep diff#106

Open
adrien-berchet wants to merge 3 commits into
mainfrom
deep_diff
Open

Deep diff#106
adrien-berchet wants to merge 3 commits into
mainfrom
deep_diff

Conversation

@adrien-berchet

Copy link
Copy Markdown
Member

This pull request introduces significant improvements to dictionary comparison functionality by replacing the dictdiffer dependency with deepdiff, 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:

  • Replaced the dictdiffer dependency with deepdiff for dictionary comparisons, resulting in more robust and detailed diff reports (pyproject.toml, dir_content_diff/base_comparators.py). [1] [2] [3]
  • Implemented a custom numeric tolerance operator (_NumericToleranceOperator) to allow approximate equality for floats and numbers in dictionary diffs (dir_content_diff/base_comparators.py).
  • Refactored diff output formatting for dictionaries to be clearer and more human-readable, with improved messages for added, changed, and removed values (dir_content_diff/base_comparators.py, README.md). [1] [2] [3]

Pre-commit and Dependency Updates:

  • Updated pre-commit hooks and related dependencies to their latest versions in .pre-commit-config.yaml for improved linting and formatting. [1] [2] [3]
  • Added a [dependency-groups] section to pyproject.toml to define development dependencies.

Documentation and Miscellaneous:

  • Updated Sphinx intersphinx mapping to reference deepdiff documentation instead of dictdiffer (docs/source/conf.py).
  • Fixed a logic bug in dir_content_diff/core.py to properly handle file comparison results (dir_content_diff/core.py).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 with DeepDiff plus 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 thread dir_content_diff/base_comparators.py Outdated
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)
)
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.

2 participants