Skip to content

compare datetime.date as numbers #331

@mrxra

Description

@mrxra

Please checkout the F.A.Q page before creating a bug ticket to make sure it is not already addressed.

Describe the bug
comparing datastructures that contain numbers and datetime.date objects raise a TypeError when certain flags related to number comparisons are set (e.g. math_epsilon).
it appears some values of the datetime module are treated as plain numbers

numbers = only_numbers + datetimes

I assume this causes datetime.date to be compared by DeepDiff._diff_numbers rather than DeepDiff._diff_datetimes (as I would expect)
self._diff_datetimes(level)

To Reproduce

import datetime
from deepdiff import DeepDiff
# passes
DeepDiff(datetime.datetime(2022, 1, 1), datetime.datetime(2022, 1, 1), math_epsilon=0.001)
# raises TypeError: must be real number, not datetime.date
DeepDiff(datetime.date(2022, 1, 1), datetime.date(2022, 1, 1), math_epsilon=0.001)

Expected behavior
No exception should be raised, the values should be detected as equal/unchanged. flags that impact number comparisons (math_epsion, precision flags,...) should probably not impact datetime comparisons

OS, DeepDiff version and Python version (please complete the following information):

  • DeepDiff 5.8.1
  • Python 3.8
  • OS: Ubuntu (running in WSL2)
  • Version 18.04.5 LTS

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions