Skip to content

Commit 734ef9b

Browse files
Refactor to _cells_match and simplify logic
1 parent fc7e68f commit 734ef9b

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

sqlmesh/core/console.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ def show_row_diff(
19081908
# Filter to retain non identical-valued rows
19091909
column_table = column_table[
19101910
column_table.apply(
1911-
lambda row: _compare_df_cells(row[source_column], row[target_column]),
1911+
lambda row: not _cells_match(row[source_column], row[target_column]),
19121912
axis=1,
19131913
)
19141914
]
@@ -2042,23 +2042,16 @@ def show_linter_violations(
20422042
self.log_warning(msg)
20432043

20442044

2045-
def _compare_df_cells(x: t.Any, y: t.Any) -> bool:
2046-
"""Helper function to compare two cells and returns true if they're not equal, handling array objects."""
2045+
def _cells_match(x: t.Any, y: t.Any) -> bool:
2046+
"""Helper function to compare two cells and returns true if they're equal, handling array objects."""
20472047
if x is None or y is None:
2048-
return x != y
2048+
return x == y
20492049

2050-
# Convert any array-like object to list for consistent comparison
2051-
def to_list(val: t.Any) -> t.Any:
2052-
return list(val) if isinstance(val, (pd.Series, np.ndarray, list, tuple, set)) else val
2050+
# Convert array-like objects to list for consistent comparison
2051+
def _normalize(val: t.Any) -> t.Any:
2052+
return list(val) if isinstance(val, (pd.Series, np.ndarray)) else val
20532053

2054-
x = to_list(x)
2055-
y = to_list(y)
2056-
if isinstance(x, list) and isinstance(y, list):
2057-
if len(x) != len(y):
2058-
return True
2059-
return any(a != b for a, b in zip(x, y))
2060-
2061-
return x != y
2054+
return _normalize(x) == _normalize(y)
20622055

20632056

20642057
def add_to_layout_widget(target_widget: LayoutWidget, *widgets: widgets.Widget) -> LayoutWidget:

0 commit comments

Comments
 (0)