Skip to content

Commit 514e025

Browse files
authored
Merge pull request #504 from vmatt/patch-1
Only lower if clean_key is instance of str
2 parents f86033f + 85adbd2 commit 514e025

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

deepdiff/diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def _get_clean_to_keys_mapping(self, keys, level):
556556
clean_key = KEY_TO_VAL_STR.format(type_, clean_key)
557557
else:
558558
clean_key = key
559-
if self.ignore_string_case:
559+
if self.ignore_string_case and isinstance(clean_key, str):
560560
clean_key = clean_key.lower()
561561
if clean_key in result:
562562
logger.warning(('{} and {} in {} become the same key when ignore_numeric_type_changes'

tests/test_diff_text.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,3 +2200,25 @@ class MyDataClass:
22002200

22012201
diff = DeepDiff(t1, t2, exclude_regex_paths=["any"])
22022202
assert {'values_changed': {'root[MyDataClass(val=2,val2=4)]': {'new_value': 10, 'old_value': 20}}} == diff
2203+
2204+
2205+
def test_group_by_with_none_key_and_ignore_case(self):
2206+
"""Test that group_by works with None keys when ignore_string_case is True"""
2207+
dict1 = [{'txt_field': 'FULL_NONE', 'group_id': None}, {'txt_field': 'FULL', 'group_id': 'a'}]
2208+
dict2 = [{'txt_field': 'PARTIAL_NONE', 'group_id': None}, {'txt_field': 'PARTIAL', 'group_id': 'a'}]
2209+
2210+
diff = DeepDiff(
2211+
dict1,
2212+
dict2,
2213+
ignore_order=True,
2214+
group_by='group_id',
2215+
ignore_string_case=True
2216+
)
2217+
2218+
expected = {'values_changed': {"root[None]['txt_field']":
2219+
{'new_value': 'partial_none', 'old_value': 'full_none'},
2220+
"root['a']['txt_field']":
2221+
{'new_value': 'partial', 'old_value': 'full'}
2222+
}
2223+
}
2224+
assert expected == diff

0 commit comments

Comments
 (0)