Debian Codegraph @

docs/diff_doc.rst

raw
1 :orphan:
2
3 .. |qluster_link| raw:: html
4
5 <a href="/qluster"><strong>Qluster</strong></a>
6
7 .. admonition:: DeepDiff is now part of |qluster_link|.
8
9 *If you're building workflows around data validation and correction,* `Qluster </qluster>`__ *gives your team a structured way to manage rules, review failures, approve fixes, and reuse decisions—without building the entire system from scratch.*
10
11 DeepDiff Module
12 ===============
13
14 Deep Difference of dictionaries, iterables, strings and almost any other object.
15 It will recursively look for all the changes.
16
17 **Parameters**
18
19 t1 : A dictionary, list, string or any python object that has __dict__ or __slots__
20 This is the first item to be compared to the second item
21
22 t2 : dictionary, list, string or almost any python object that has __dict__ or __slots__
23 The second item is to be compared to the first one
24
25 cutoff_distance_for_pairs : 1 >= float >= 0, default=0.3
26 :ref:`cutoff_distance_for_pairs_label` What is the threshold to consider 2 items as pairs.
27 Note that it is only used when ignore_order = True.
28
29 cutoff_intersection_for_pairs : 1 >= float >= 0, default=0.7
30 :ref:`cutoff_intersection_for_pairs_label` What is the threshold to calculate pairs of items between 2 iterables.
31 For example 2 iterables that have nothing in common, do not need their pairs to be calculated.
32 Note that it is only used when ignore_order = True.
33
34 cache_size : int >= 0, default=0
35 :ref:`cache_size_label` Cache size to be used to improve the performance. A cache size of zero means it is disabled.
36 Using the cache_size can dramatically improve the diff performance especially for the nested objects at the cost of more memory usage.
37
38 cache_purge_level: int, 0, 1, or 2. default=1
39 :ref:`cache_purge_level` defines what objects in DeepDiff should be deleted to free the memory once the diff object is calculated. If this value is set to zero, most of the functionality of the diff object is removed and the most memory is released. A value of 1 preserves all the functionalities of the diff object. A value of 2 also preserves the cache and hashes that were calculated during the diff calculations. In most cases the user does not need to have those objects remained in the diff unless for investigation purposes.
40
41 cache_tuning_sample_size : int >= 0, default = 0
42 :ref:`cache_tuning_sample_size_label` This is an experimental feature. It works hands in hands with the :ref:`cache_size_label`. When cache_tuning_sample_size is set to anything above zero, it will sample the cache usage with the passed sample size and decide whether to use the cache or not. And will turn it back on occasionally during the diffing process. This option can be useful if you are not sure if you need any cache or not. However you will gain much better performance with keeping this parameter zero and running your diff with different cache sizes and benchmarking to find the optimal cache size.
43
44 custom_operators : BaseOperator subclasses, default = None
45 :ref:`custom_operators_label` if you are considering whether they are fruits or not. In that case, you can pass a *custom_operators* for the job.
46
47 default_timezone : datetime.timezone subclasses or pytz datetimes, default = datetime.timezone.utc
48 :ref:`default_timezone_label` defines the default timezone. If a datetime is timezone naive, which means it doesn't have a timezone, we assume the datetime is in this timezone. Also any datetime that has a timezone will be converted to this timezone so the datetimes can be compared properly all in the same timezone. Note that Python's default behavior assumes the default timezone is your local timezone. DeepDiff's default is UTC, not your local time zone.
49
50 encodings: List, default = None
51 :ref:`encodings_label` Character encodings to iterate through when we convert bytes into strings. You may want to pass an explicit list of encodings in your objects if you start getting UnicodeDecodeError from DeepHash. Also check out :ref:`ignore_encoding_errors_label` if you can get away with ignoring these errors and don't want to bother with an explicit list of encodings but it will come at the price of slightly less accuracy of the final results. Example: encodings=["utf-8", "latin-1"]
52
53 exclude_paths: list, default = None
54 :ref:`exclude_paths_label`
55 List of paths to exclude from the report. If only one item, you can path it as a string.
56
57 exclude_regex_paths: list, default = None
58 :ref:`exclude_regex_paths_label`
59 List of string regex paths or compiled regex paths objects to exclude from the report. If only one item, you can pass it as a string or regex compiled object.
60
61 exclude_types: list, default = None
62 :ref:`exclude_types_label`
63 List of object types to exclude from the report.
64
65 exclude_obj_callback: function, default = None
66 :ref:`exclude_obj_callback_label`
67 A function that takes the object and its path and returns a Boolean. If True is returned, the object is excluded from the results, otherwise it is included.
68 This is to give the user a higher level of control than one can achieve via exclude_paths, exclude_regex_paths or other means.
69
70 exclude_obj_callback_strict: function, default = None
71 :ref:`exclude_obj_callback_strict_label`
72 A function that works the same way as exclude_obj_callback, but excludes elements from the result only if the function returns True for both elements.
73
74 include_paths: list, default = None
75 :ref:`include_paths_label`
76 List of the only paths to include in the report. If only one item is in the list, you can pass it as a string.
77
78 include_obj_callback: function, default = None
79 :ref:`include_obj_callback_label`
80 A function that takes the object and its path and returns a Boolean. If True is returned, the object is included in the results, otherwise it is excluded.
81 This is to give the user a higher level of control than one can achieve via include_paths.
82
83 include_obj_callback_strict: function, default = None
84 :ref:`include_obj_callback_strict_label`
85 A function that works the same way as include_obj_callback, but includes elements in the result only if the function returns True for both elements.
86
87 get_deep_distance: Boolean, default = False
88 :ref:`get_deep_distance_label` will get you the deep distance between objects. The distance is a number between 0 and 1 where zero means there is no diff between the 2 objects and 1 means they are very different. Note that this number should only be used to compare the similarity of 2 objects and nothing more. The algorithm for calculating this number may or may not change in the future releases of DeepDiff.
89
90 group_by: String or a list of size 2, default=None
91 :ref:`group_by_label` can be used when dealing with the list of dictionaries. It converts them from lists to a single dictionary with the key defined by group_by. The common use case is when reading data from a flat CSV, and the primary key is one of the columns in the CSV. We want to use the primary key instead of the CSV row number to group the rows. The group_by can do 2D group_by by passing a list of 2 keys.
92
93 group_by_sort_key: String or a function
94 :ref:`group_by_sort_key_label` is used to define how dictionaries are sorted if multiple ones fall under one group. When this parameter is used, group_by converts the lists of dictionaries into a dictionary of keys to lists of dictionaries. Then, :ref:`group_by_sort_key_label` is used to sort between the list.
95
96 hasher: default = DeepHash.sha256hex
97 Hash function to be used. If you don't want SHA256, you can use your own hash function
98 by passing hasher=hash. This is for advanced usage and normally you don't need to modify it.
99
100 ignore_order : Boolean, default=False
101 :ref:`ignore_order_label` ignores order of elements when comparing iterables (lists)
102 Normally ignore_order does not report duplicates and repetition changes.
103 In order to report repetitions, set report_repetition=True in addition to ignore_order=True
104
105 ignore_order_func : Function, default=None
106 :ref:`ignore_order_func_label` Sometimes single *ignore_order* parameter is not enough to do a diff job,
107 you can use *ignore_order_func* to determine whether the order of certain paths should be ignored
108
109 ignore_string_type_changes: Boolean, default = False
110 :ref:`ignore_string_type_changes_label`
111 Whether to ignore string type changes or not. For example b"Hello" vs. "Hello" are considered the same if ignore_string_type_changes is set to True.
112
113 ignore_numeric_type_changes: Boolean, default = False
114 :ref:`ignore_numeric_type_changes_label`
115 Whether to ignore numeric type changes or not. For example 10 vs. 10.0 are considered the same if ignore_numeric_type_changes is set to True.
116
117 ignore_type_in_groups: Tuple or List of Tuples, default = None
118 :ref:`ignore_type_in_groups_label`
119 ignores types when t1 and t2 are both within the same type group.
120
121 ignore_type_subclasses: Boolean, default = False
122 :ref:`ignore_type_subclasses_label`
123 ignore type (class) changes when dealing with the subclasses of classes that were marked to be ignored.
124
125 .. Note::
126 ignore_type_subclasses was incorrectly doing the reverse of its job up until DeepDiff 6.7.1
127 Please make sure to flip it in your use cases, when upgrading from older versions to 7.0.0 or above.
128
129 ignore_uuid_types: Boolean, default = False
130 :ref:`ignore_uuid_types_label`
131 Whether to ignore UUID vs string type differences when comparing. When set to True, comparing a UUID object with its string representation will not report as a type change.
132
133 ignore_string_case: Boolean, default = False
134 :ref:`ignore_string_case_label`
135 Whether to be case-sensitive or not when comparing strings. By setting ignore_string_case=True, strings will be compared case-insensitively.
136
137 ignore_nan_inequality: Boolean, default = False
138 :ref:`ignore_nan_inequality_label`
139 Whether to ignore float('nan') inequality in Python.
140
141
142 ignore_private_variables: Boolean, default = True
143 :ref:`ignore_private_variables_label`
144 Whether to exclude the private variables in the calculations or not. It only affects variables that start with double underscores (__).
145
146
147 ignore_encoding_errors: Boolean, default = False
148 :ref:`ignore_encoding_errors_label` If you want to get away with UnicodeDecodeError without passing explicit character encodings, set this option to True. If you want to make sure the encoding is done properly, keep this as False and instead pass an explicit list of character encodings to be considered via the :ref:`encodings_label` parameter.
149
150
151 zip_ordered_iterables: Boolean, default = False
152 :ref:`zip_ordered_iterables_label`:
153 When comparing ordered iterables such as lists, DeepDiff tries to find the smallest difference between the two iterables to report. That means that items in the two lists are not paired individually in the order of appearance in the iterables. Sometimes, that is not the desired behavior. Set this flag to True to make DeepDiff pair and compare the items in the iterables in the order they appear.
154
155 iterable_compare_func:
156 :ref:`iterable_compare_func_label`:
157 There are times that we want to guide DeepDiff as to what items to compare with other items. In such cases we can pass a iterable_compare_func that takes a function pointer to compare two items. The function takes three parameters (x, y, level) and should return True if it is a match, False if it is not a match or raise CannotCompare if it is unable to compare the two.
158
159
160 log_frequency_in_sec: Integer, default = 0
161 :ref:`log_frequency_in_sec_label`
162 How often to log the progress. The default of 0 means logging progress is disabled.
163 If you set it to 20, it will log every 20 seconds. This is useful only when running DeepDiff
164 on massive objects that will take a while to run. If you are only dealing with small objects, keep it at 0 to disable progress logging.
165
166 log_scale_similarity_threshold: float, default = 0.1
167 :ref:`use_log_scale_label` along with :ref:`log_scale_similarity_threshold_label` can be used to ignore small changes in numbers by comparing their differences in logarithmic space. This is different than ignoring the difference based on significant digits.
168
169 log_stacktrace: Boolean, default = False
170 If True, we log the stacktrace when logging errors. Otherwise we only log the error message.
171
172 max_passes: Integer, default = 10000000
173 :ref:`max_passes_label` defined the maximum number of passes to run on objects to pin point what exactly is different. This is only used when ignore_order=True. A new pass is started each time 2 iterables are compared in a way that every single item that is different from the first one is compared to every single item that is different in the second iterable.
174
175 max_diffs: Integer, default = None
176 :ref:`max_diffs_label` defined the maximum number of diffs to run on objects to pin point what exactly is different. This is only used when ignore_order=True
177
178 math_epsilon: Decimal, default = None
179 :ref:`math_epsilon_label` uses Python's built in Math.isclose. It defines a tolerance value which is passed to math.isclose(). Any numbers that are within the tolerance will not report as being different. Any numbers outside of that tolerance will show up as different.
180
181 number_format_notation : string, default="f"
182 :ref:`number_format_notation_label` is what defines the meaning of significant digits. The default value of "f" means the digits AFTER the decimal point. "f" stands for fixed point. The other option is "e" which stands for exponent notation or scientific notation.
183
184 number_to_string_func : function, default=None
185 :ref:`number_to_string_func_label` is an advanced feature to give the user the full control into overriding how numbers are converted to strings for comparison. The default function is defined in https://github.com/seperman/deepdiff/blob/master/deepdiff/helper.py and is called number_to_string. You can define your own function to do that.
186
187 progress_logger: log function, default = logger.info
188 :ref:`progress_logger_label` defines what logging function to use specifically for progress reporting. This function is only used when progress logging is enabled which happens by setting log_frequency_in_sec to anything above zero.
189
190 report_repetition : Boolean, default=False
191 :ref:`report_repetition_label` reports repetitions when set True
192 It only works when ignore_order is set to True too.
193
194 significant_digits : int >= 0, default=None
195 :ref:`significant_digits_label` defines the number of digits AFTER the decimal point to be used in the comparison. However you can override that by setting the number_format_notation="e" which will make it mean the digits in scientific notation.
196
197 truncate_datetime: string, default = None
198 :ref:`truncate_datetime_label` can take value one of 'second', 'minute', 'hour', 'day' and truncate with this value datetime objects before hashing it
199
200 threshold_to_diff_deeper: float, default = 0.33
201 :ref:`threshold_to_diff_deeper_label` is a number between 0 and 1. When comparing dictionaries that have a small intersection of keys, we will report the dictionary as a new_value instead of reporting individual keys changed. If you set it to zero, you get the same results as DeepDiff 7.0.1 and earlier, which means this feature is disabled. The new default is 0.33 which means if less that one third of keys between dictionaries intersect, report it as a new object.
202
203 use_enum_value: Boolean, default=False
204 :ref:`use_enum_value_label` makes it so when diffing enum, we use the enum's value. It makes it so comparing an enum to a string or any other value is not reported as a type change.
205
206 use_log_scale: Boolean, default=False
207 :ref:`use_log_scale_label` along with :ref:`log_scale_similarity_threshold_label` can be used to ignore small changes in numbers by comparing their differences in logarithmic space. This is different than ignoring the difference based on significant digits.
208
209 verbose_level: 2 >= int >= 0, default = 1
210 Higher verbose level shows you more details.
211 For example verbose level 1 shows what dictionary item are added or removed.
212 And verbose level 2 shows the value of the items that are added or removed too.
213
214 view: string, default = text
215 :ref:`view_label`
216 Views are different "formats" of results. Each view comes with its own features.
217 The choices are text (the default) and tree.
218 The text view is the original format of the results.
219 The tree view allows you to traverse through the tree of results. So you can traverse through the tree and see what items were compared to what.
220
221
222 **Returns**
223
224 A DeepDiff object that has already calculated the difference of the 2 items. The format of the object is chosen by the view parameter.
225
226 **Supported data types**
227
228 int, string, unicode, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple, Numpy, custom objects and more!
229
230 .. Note::
231 |:mega:| **Please fill out our** `fast 5-question survey <https://forms.gle/E6qXexcgjoKnSzjB8>`__ so that we can learn how & why you use DeepDiff, and what improvements we should make. Thank you! |:dancers:|