GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Bug-Fix: TypeError in _get_numbers_distance() when ignore_order = True by Dhanvantari · Pull Request #284 · qlustered/deepdiff

Conversation

@Dhanvantari

@Dhanvantari Dhanvantari commented Dec 8, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

For lists comparison when ignore_order is True, TypeError occurs as type(_max) = float it doesn't match with other numbers like Decimal.
The cast should be done when numbers are not 'float' type.
Example:

from decimal import Decimal
from deepdiff import DeepDiff

def test_deep_diff():
    a = {'a': [Decimal(1), Decimal(2), Decimal(3), Decimal(5)]}
    b = {'a': [Decimal(3), Decimal(2), Decimal(1), Decimal(4)]}
    print(DeepDiff(a, b, ignore_order = True, cutoff_distance_for_pairs=1))

def main():
    test_deep_diff()

if __name__ == "__main__":
    main()

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Dhanvantari
Fix: TypeError in _get_numbers_distance when ignore_order
6b7ee52
For lists comparison when ignore_order is True, TypeError occurs as type(_max) = float it doesnt match with other numbers like Decimal.
The cast should be done when numbers are not 'float' type.
Example: 

```
from decimal import Decimal
from deepdiff import DeepDiff
from deepdiff.helper import number_to_string

def custom_number_to_string(number, *args, **kwargs):
    if type(number) == Decimal:
        number = float(number)
    return number_to_string(number, *args, **kwargs)

def test_deep_diff():
    # a = {'a': [datetime.datetime(2020, 5, 17), datetime.datetime(2020, 6, 17), datetime.datetime(2020, 7, 17)]}
    # b = {'a': [datetime.datetime(2020, 7, 17), datetime.datetime(2020, 6, 17), datetime.datetime(2020, 5, 17)]}
    a = {'a': [Decimal(1), Decimal(2), Decimal(3), Decimal(5)]}
    b = {'a': [Decimal(3), Decimal(2), Decimal(1), Decimal(4)]}
    print(DeepDiff(a, b, ignore_order = True, cutoff_distance_for_pairs=1, number_to_string_func=custom_number_to_string))

def main():
    test_deep_diff()

if __name__ == "__main__":
    main()

```
@seperman

seperman commented Dec 17, 2021

Copy link
Copy Markdown
Member

@Dhanvantari Haha, thanks for catching that.

Dhanvantari reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seperman seperman added the bug label Dec 17, 2021
@seperman

seperman commented Dec 17, 2021

Copy link
Copy Markdown
Member

One test fails but I'm gonna fix it.

Dhanvantari reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@seperman
seperman merged commit e2de588 into qlustered:dev Dec 17, 2021
@seperman seperman mentioned this pull request Dec 17, 2021
DeepDiff 5.7.0 #287
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

bug

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Dhanvantari @seperman
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.