Skip to content

Commit

Permalink
Merge pull request #504 from vmatt/patch-1
Browse files Browse the repository at this point in the history
Only lower if clean_key is instance of str
  • Loading branch information
seperman authored Dec 14, 2024
2 parents f86033f + 85adbd2 commit 514e025
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion deepdiff/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def _get_clean_to_keys_mapping(self, keys, level):
clean_key = KEY_TO_VAL_STR.format(type_, clean_key)
else:
clean_key = key
if self.ignore_string_case:
if self.ignore_string_case and isinstance(clean_key, str):
clean_key = clean_key.lower()
if clean_key in result:
logger.warning(('{} and {} in {} become the same key when ignore_numeric_type_changes'
Expand Down
22 changes: 22 additions & 0 deletions tests/test_diff_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -2200,3 +2200,25 @@ class MyDataClass:

diff = DeepDiff(t1, t2, exclude_regex_paths=["any"])
assert {'values_changed': {'root[MyDataClass(val=2,val2=4)]': {'new_value': 10, 'old_value': 20}}} == diff


def test_group_by_with_none_key_and_ignore_case(self):
"""Test that group_by works with None keys when ignore_string_case is True"""
dict1 = [{'txt_field': 'FULL_NONE', 'group_id': None}, {'txt_field': 'FULL', 'group_id': 'a'}]
dict2 = [{'txt_field': 'PARTIAL_NONE', 'group_id': None}, {'txt_field': 'PARTIAL', 'group_id': 'a'}]

diff = DeepDiff(
dict1,
dict2,
ignore_order=True,
group_by='group_id',
ignore_string_case=True
)

expected = {'values_changed': {"root[None]['txt_field']":
{'new_value': 'partial_none', 'old_value': 'full_none'},
"root['a']['txt_field']":
{'new_value': 'partial', 'old_value': 'full'}
}
}
assert expected == diff

0 comments on commit 514e025

Please sign in to comment.