Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated compare_dictionaries #5385

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
77 changes: 0 additions & 77 deletions qcodes/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,80 +41,3 @@ def warn_units(class_name: str, instance: object) -> None:
f"`units` is deprecated for the `{class_name}` "
f"class, use `unit` instead. {instance!r}"
)


@deprecate("Internal function no longer part of the public qcodes api")
def compare_dictionaries(
dict_1: dict[Hashable, Any],
dict_2: dict[Hashable, Any],
dict_1_name: Optional[str] = "d1",
dict_2_name: Optional[str] = "d2",
path: str = "",
) -> tuple[bool, str]:
"""
Compare two dictionaries recursively to find non matching elements.

Args:
dict_1: First dictionary to compare.
dict_2: Second dictionary to compare.
dict_1_name: Optional name of the first dictionary used in the
differences string.
dict_2_name: Optional name of the second dictionary used in the
differences string.
Returns:
Tuple: Are the dicts equal and the difference rendered as
a string.

"""
err = ""
key_err = ""
value_err = ""
old_path = path
for k in dict_1.keys():
path = old_path + "[%s]" % k
if k not in dict_2.keys():
key_err += f"Key {dict_1_name}{path} not in {dict_2_name}\n"
else:
if isinstance(dict_1[k], dict) and isinstance(dict_2[k], dict):
err += compare_dictionaries(
dict_1[k], dict_2[k], dict_1_name, dict_2_name, path
)[1]
else:
match = dict_1[k] == dict_2[k]

# if values are equal-length numpy arrays, the result of
# "==" is a bool array, so we need to 'all' it.
# In any other case "==" returns a bool
# TODO(alexcjohnson): actually, if *one* is a numpy array
# and the other is another sequence with the same entries,
# this will compare them as equal. Do we want this, or should
# we require exact type match?
if hasattr(match, "all"):
match = match.all()

if not match:
value_err += (
'Value of "{}{}" ("{}", type"{}") not same as\n'
' "{}{}" ("{}", type"{}")\n\n'
).format(
dict_1_name,
path,
dict_1[k],
type(dict_1[k]),
dict_2_name,
path,
dict_2[k],
type(dict_2[k]),
)

for k in dict_2.keys():
path = old_path + f"[{k}]"
if k not in dict_1.keys():
key_err += f"Key {dict_2_name}{path} not in {dict_1_name}\n"

dict_differences = key_err + value_err + err
if len(dict_differences) == 0:
dicts_equal = True
else:
dicts_equal = False
return dicts_equal, dict_differences