Skip to content

Commit

Permalink
fix(api): ensure memtable schema and columns match (#10617)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepyaman authored Dec 27, 2024
1 parent 013c79b commit f1837b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ibis/expr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ def memtable(
"passing `columns` and schema` is ambiguous; "
"pass one or the other but not both"
)

if schema is not None:
import ibis

schema = ibis.schema(schema)

return _memtable(data, name=name, schema=schema, columns=columns)


Expand Down
9 changes: 9 additions & 0 deletions ibis/expr/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ def test_duplicate_columns_in_memtable_not_allowed():
ibis.memtable(df)


def test_memtable_column_names_match_schema():
pd = pytest.importorskip("pandas")

df = pd.DataFrame([[1, 2], [3, 4]])
schema = {"a": "int64", "b": "int64"}
t = ibis.memtable(df, schema=schema)
assert t.op().data.to_frame().columns.tolist() == ["a", "b"]


@pytest.mark.parametrize(
"op",
[
Expand Down

0 comments on commit f1837b7

Please sign in to comment.