MCPcopy Index your code
hub / github.com/pydata/xarray / diff_array_repr

Function diff_array_repr

xarray/core/formatting.py:1056–1094  ·  view source on GitHub ↗
(a, b, compat)

Source from the content-addressed store, hash-verified

1054
1055
1056def diff_array_repr(a, b, compat):
1057 # used for DataArray, Variable and IndexVariable
1058 summary = [
1059 f"Left and right {type(a).__name__} objects are not {_compat_to_str(compat)}"
1060 ]
1061
1062 if dims_diff := diff_dim_summary(a, b):
1063 summary.append(dims_diff)
1064
1065 if callable(compat):
1066 equiv = compat
1067 else:
1068 equiv = array_equiv
1069
1070 if not equiv(a.data, b.data):
1071 temp = [wrap_indent(short_array_repr(obj), start=" ") for obj in (a, b)]
1072 diff_data_repr = [
1073 ab_side + "\n" + ab_data_repr
1074 for ab_side, ab_data_repr in zip(("L", "R"), temp, strict=True)
1075 ]
1076 summary += ["Differing values:"] + diff_data_repr
1077
1078 if hasattr(a, "coords"):
1079 col_width = _calculate_col_width(set(a.coords) | set(b.coords))
1080 if coords_diff := diff_coords_repr(
1081 a.coords, b.coords, compat, col_width=col_width
1082 ):
1083 summary.append(coords_diff)
1084
1085 if compat == "identical":
1086 if hasattr(a, "xindexes") and (
1087 indexes_diff := diff_indexes_repr(a.xindexes, b.xindexes)
1088 ):
1089 summary.append(indexes_diff)
1090
1091 if attrs_diff := diff_attrs_repr(a.attrs, b.attrs, compat):
1092 summary.append(attrs_diff)
1093
1094 return "\n".join(summary)
1095
1096
1097def diff_treestructure(a: DataTree, b: DataTree) -> str | None:

Callers

nothing calls this directly

Calls 9

typeFunction · 0.85
_compat_to_strFunction · 0.85
diff_dim_summaryFunction · 0.85
wrap_indentFunction · 0.85
short_array_reprFunction · 0.85
_calculate_col_widthFunction · 0.85
diff_coords_reprFunction · 0.85
diff_indexes_reprFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…