Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group_by fails if group_by key is None #503

Open
vmatt opened this issue Nov 18, 2024 · 0 comments · Fixed by #504
Open

group_by fails if group_by key is None #503

vmatt opened this issue Nov 18, 2024 · 0 comments · Fixed by #504

Comments

@vmatt
Copy link
Contributor

vmatt commented Nov 18, 2024

Describe the bug
When using group_by using a key which is nullable, it cannot do group_by on None, because of this line in diff.py

if self.ignore_string_case:
        clean_key = clean_key.lower()

AttributeError: 'NoneType' object has no attribute 'lower'

To Reproduce

from deepdiff import DeepDiff

# First dictionary
dict1 =[{'txt_field': 'FULL', 'group_id': None}]

# Second dictionary with some differences
dict2 = [{'txt_field': 'FULL', 'group_id': 'a'}]

# Compare the dictionaries
diff = DeepDiff(
    dict1,
    dict2,
    ignore_order=True,
    group_by='group_id',
    ignore_numeric_type_changes=True,
    significant_digits=1,
    ignore_string_case=True,
    ignore_nan_inequality=True,

)

print("Differences found:", diff)

Expected behavior
If the group_by key is None, it should group_by all None/NULL fields where the group_by key is instance of string.

if self.ignore_string_case and isinstance(clean_key,str):
        clean_key = clean_key.lower()

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

  • OS: MacOS
  • Version: 15
  • Python Version: 3.11
  • DeepDiff Version: 8.0.1
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 a pull request may close this issue.

1 participant