From f6c7bcb1ab65b65a8d0ff49f6349099b99e63c8a Mon Sep 17 00:00:00 2001 From: Mate Valko <3168272+vmatt@users.noreply.github.com> Date: Mon, 18 Nov 2024 11:22:14 +0100 Subject: [PATCH 1/2] Only lower if clean_key is instance of str --- deepdiff/diff.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deepdiff/diff.py b/deepdiff/diff.py index 4dfec50..da2ea8e 100755 --- a/deepdiff/diff.py +++ b/deepdiff/diff.py @@ -530,7 +530,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' From 85adbd2e27bff66ee530ad95a7a6c51f627d4096 Mon Sep 17 00:00:00 2001 From: Mate Valko Date: Sat, 7 Dec 2024 23:21:27 +0100 Subject: [PATCH 2/2] add tests for group_by None cases --- tests/test_diff_text.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_diff_text.py b/tests/test_diff_text.py index ec6f66b..b41384d 100755 --- a/tests/test_diff_text.py +++ b/tests/test_diff_text.py @@ -2147,3 +2147,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