Skip to content

Commit

Permalink
fix(ir): ensure that schema column order matters
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Apr 27, 2024
1 parent b48f451 commit 4930e6b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ibis/backends/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,3 +1608,14 @@ def test_json_to_pyarrow(con):
if val is not None
}
assert result == expected


def test_schema_with_caching(alltypes):
t1 = alltypes.limit(5).select("int_col", "string_col")
t2 = alltypes.limit(5).select("string_col", "int_col")

pt1 = t1.cache()
pt2 = t2.cache()

assert pt1.schema() == ibis.schema(dict(int_col="int32", string_col="string"))
assert pt2.schema() == ibis.schema(dict(string_col="string", int_col="int32"))
5 changes: 5 additions & 0 deletions ibis/common/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ def __init__(self, *args, **kwargs):
def __hash__(self) -> int:
return self.__precomputed_hash__

def __eq__(self, other: Any) -> bool:
if not isinstance(other, collections.abc.Mapping):
return NotImplemented
return collections.OrderedDict(self) == collections.OrderedDict(other)

def __setitem__(self, key: K, value: V) -> None:
raise TypeError("'FrozenDict' object does not support item assignment")

Expand Down
9 changes: 9 additions & 0 deletions ibis/expr/schema.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import collections
from collections.abc import Iterable, Iterator, Mapping
from typing import TYPE_CHECKING, Any, Union

Expand Down Expand Up @@ -90,6 +91,14 @@ def equals(self, other: Schema) -> bool:
)
return self == other

def __hash__(self) -> int:
return super().__hash__()

def __eq__(self, other):
if not isinstance(other, Mapping):
return NotImplemented

Check warning on line 99 in ibis/expr/schema.py

View check run for this annotation

Codecov / codecov/patch

ibis/expr/schema.py#L99

Added line #L99 was not covered by tests
return collections.OrderedDict(self) == collections.OrderedDict(other)

@classmethod
def from_tuples(
cls,
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/tests/test_dereference.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def test_dereference_project():
expected = dereference_expect(
{
p.int_col: p.int_col,
p.double_col: p.double_col,
t.int_col: p.int_col,
p.double_col: p.double_col,
t.double_col: p.double_col,
}
)
Expand Down

0 comments on commit 4930e6b

Please sign in to comment.