@@ -98,6 +98,7 @@ def _report_progress(_stats, progress_logger, duration):
98
98
'number_format_notation' ,
99
99
'ignore_string_type_changes' ,
100
100
'ignore_numeric_type_changes' ,
101
+ 'use_enum_value' ,
101
102
'ignore_type_in_groups' ,
102
103
'ignore_type_subclasses' ,
103
104
'ignore_string_case' ,
@@ -116,6 +117,7 @@ class DeepDiff(ResultDict, SerializationMixin, DistanceMixin, Base):
116
117
def __init__ (self ,
117
118
t1 : Any ,
118
119
t2 : Any ,
120
+ _original_type = None ,
119
121
cache_purge_level : int = 1 ,
120
122
cache_size : int = 0 ,
121
123
cache_tuning_sample_size : int = 0 ,
@@ -126,9 +128,6 @@ def __init__(self,
126
128
exclude_obj_callback : Optional [Callable ]= None ,
127
129
exclude_obj_callback_strict : Optional [Callable ]= None ,
128
130
exclude_paths : Union [str , List [str ]]= None ,
129
- include_obj_callback : Optional [Callable ]= None ,
130
- include_obj_callback_strict : Optional [Callable ]= None ,
131
- include_paths : Union [str , List [str ]]= None ,
132
131
exclude_regex_paths : Union [str , List [str ], Pattern [str ], List [Pattern [str ]], None ]= None ,
133
132
exclude_types : Optional [List [Any ]]= None ,
134
133
get_deep_distance : bool = False ,
@@ -146,8 +145,10 @@ def __init__(self,
146
145
ignore_string_type_changes : bool = False ,
147
146
ignore_type_in_groups : Optional [List [Tuple ]]= None ,
148
147
ignore_type_subclasses : bool = False ,
148
+ include_obj_callback : Optional [Callable ]= None ,
149
+ include_obj_callback_strict : Optional [Callable ]= None ,
150
+ include_paths : Union [str , List [str ]]= None ,
149
151
iterable_compare_func : Optional [Callable ]= None ,
150
- zip_ordered_iterables : bool = False ,
151
152
log_frequency_in_sec : int = 0 ,
152
153
math_epsilon : Optional [float ]= None ,
153
154
max_diffs : Optional [int ]= None ,
@@ -157,10 +158,12 @@ def __init__(self,
157
158
progress_logger : Callable = logger .info ,
158
159
report_repetition : bool = False ,
159
160
significant_digits : Optional [int ]= None ,
161
+ threshold_to_diff_deeper : float = 0 ,
160
162
truncate_datetime : Optional [str ]= None ,
163
+ use_enum_value : bool = False ,
161
164
verbose_level : int = 1 ,
162
165
view : str = TEXT_VIEW ,
163
- _original_type = None ,
166
+ zip_ordered_iterables : bool = False ,
164
167
_parameters = None ,
165
168
_shared_parameters = None ,
166
169
** kwargs ):
@@ -175,7 +178,7 @@ def __init__(self,
175
178
"view, hasher, hashes, max_passes, max_diffs, zip_ordered_iterables, "
176
179
"cutoff_distance_for_pairs, cutoff_intersection_for_pairs, log_frequency_in_sec, cache_size, "
177
180
"cache_tuning_sample_size, get_deep_distance, group_by, group_by_sort_key, cache_purge_level, "
178
- "math_epsilon, iterable_compare_func, _original_type, "
181
+ "math_epsilon, iterable_compare_func, use_enum_value, _original_type, threshold_to_diff_deeper , "
179
182
"ignore_order_func, custom_operators, encodings, ignore_encoding_errors, "
180
183
"_parameters and _shared_parameters." ) % ', ' .join (kwargs .keys ()))
181
184
@@ -193,6 +196,8 @@ def __init__(self,
193
196
self .ignore_numeric_type_changes = ignore_numeric_type_changes
194
197
if strings == ignore_type_in_groups or strings in ignore_type_in_groups :
195
198
ignore_string_type_changes = True
199
+ self .use_enum_value = use_enum_value
200
+ self .threshold_to_diff_deeper = threshold_to_diff_deeper
196
201
self .ignore_string_type_changes = ignore_string_type_changes
197
202
self .ignore_type_in_groups = self .get_ignore_types_in_groups (
198
203
ignore_type_in_groups = ignore_type_in_groups ,
@@ -513,6 +518,8 @@ def _get_clean_to_keys_mapping(self, keys, level):
513
518
for key in keys :
514
519
if self .ignore_string_type_changes and isinstance (key , bytes ):
515
520
clean_key = key .decode ('utf-8' )
521
+ elif self .use_enum_value and isinstance (key , Enum ):
522
+ clean_key = key .value
516
523
elif isinstance (key , numbers ):
517
524
type_ = "number" if self .ignore_numeric_type_changes else key .__class__ .__name__
518
525
clean_key = self .number_to_string (key , significant_digits = self .significant_digits ,
@@ -578,6 +585,12 @@ def _diff_dict(
578
585
t_keys_added = t2_keys - t_keys_intersect
579
586
t_keys_removed = t1_keys - t_keys_intersect
580
587
588
+ if self .threshold_to_diff_deeper :
589
+ len_keys_changed = (len (t_keys_added ) + len (t_keys_removed ))
590
+ if len_keys_changed and len (t_keys_intersect ) / len_keys_changed < self .threshold_to_diff_deeper :
591
+ self ._report_result ('values_changed' , level , local_tree = local_tree )
592
+ return
593
+
581
594
for key in t_keys_added :
582
595
if self ._count_diff () is StopIteration :
583
596
return
@@ -861,31 +874,6 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
861
874
self ._report_result ('iterable_item_added' , change_level , local_tree = local_tree )
862
875
863
876
else : # check if item value has changed
864
-
865
- # if (i != j):
866
- # # Item moved
867
- # change_level = level.branch_deeper(
868
- # x,
869
- # y,
870
- # child_relationship_class=child_relationship_class,
871
- # child_relationship_param=i,
872
- # child_relationship_param2=j
873
- # )
874
- # self._report_result('iterable_item_moved', change_level)
875
-
876
- # item_id = id(x)
877
- # if parents_ids and item_id in parents_ids:
878
- # continue
879
- # parents_ids_added = add_to_frozen_set(parents_ids, item_id)
880
-
881
- # # Go one level deeper
882
- # next_level = level.branch_deeper(
883
- # x,
884
- # y,
885
- # child_relationship_class=child_relationship_class,
886
- # child_relationship_param=j)
887
- # self._diff(next_level, parents_ids_added)
888
-
889
877
if (i != j and ((x == y ) or self .iterable_compare_func )):
890
878
# Item moved
891
879
change_level = level .branch_deeper (
@@ -1604,6 +1592,12 @@ def _diff(self, level, parents_ids=frozenset(), _original_type=None, local_tree=
1604
1592
if self .type_check_func (level .t1 , type_group ) and self .type_check_func (level .t2 , type_group ):
1605
1593
report_type_change = False
1606
1594
break
1595
+ if self .use_enum_value and isinstance (level .t1 , Enum ):
1596
+ level .t1 = level .t1 .value
1597
+ report_type_change = False
1598
+ if self .use_enum_value and isinstance (level .t2 , Enum ):
1599
+ level .t2 = level .t2 .value
1600
+ report_type_change = False
1607
1601
if report_type_change :
1608
1602
self ._diff_types (level , local_tree = local_tree )
1609
1603
return
0 commit comments