Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): ensure memtable schema and columns match #10617

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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"]

Check warning on line 152 in ibis/expr/tests/test_api.py

View check run for this annotation

Codecov / codecov/patch

ibis/expr/tests/test_api.py#L149-L152

Added lines #L149 - L152 were not covered by tests


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