Skip to content

Commit 840396e

Browse files
authored
Fix: convert lists, ndarrays to tuples when sorting unit test dataframes (#2296)
* Fix: apply _to_hashable correctly in unit tests * Attempt to fix * Fix _to_hashable to take ndarray into account
1 parent 80c3b60 commit 840396e

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

sqlmesh/core/test/definition.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,15 @@ def assert_equal(
129129
expected = expected.replace({None: np.nan})
130130

131131
def _to_hashable(x: t.Any) -> t.Any:
132-
return tuple(x) if isinstance(x, list) else x
132+
if isinstance(x, (list, np.ndarray)):
133+
return tuple(x)
134+
return str(x) if not isinstance(x, t.Hashable) else x
133135

134136
if sort:
135-
actual = (
136-
actual.apply(_to_hashable)
137-
.sort_values(by=actual.columns.to_list())
138-
.reset_index(drop=True)
139-
)
140-
expected = (
141-
expected.apply(_to_hashable)
142-
.sort_values(by=expected.columns.to_list())
143-
.reset_index(drop=True)
144-
)
145-
137+
actual = actual.apply(lambda col: col.map(_to_hashable))
138+
actual = actual.sort_values(by=actual.columns.to_list()).reset_index(drop=True)
139+
expected = expected.apply(lambda col: col.map(_to_hashable))
140+
expected = expected.sort_values(by=expected.columns.to_list()).reset_index(drop=True)
146141
try:
147142
pd.testing.assert_frame_equal(
148143
expected,

0 commit comments

Comments
 (0)