Skip to content

Commit

Permalink
fix(api): use to_pyarrow() instead of execute() when pretty print…
Browse files Browse the repository at this point in the history
…ing scalars
  • Loading branch information
cpcloud committed Sep 20, 2024
1 parent c62efce commit 05172cd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions ibis/backends/tests/test_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,18 @@ def test_no_recursion_error(con, monkeypatch):
exc.RelationError, match="The scalar expression cannot be converted"
):
repr(expr)


def test_scalar_uses_pyarrow(con, table, monkeypatch, mocker):
monkeypatch.setattr(ibis.options, "interactive", True)

execute_spy = mocker.spy(con, "execute")
to_pyarrow_spy = mocker.spy(con, "to_pyarrow")

repr(table.limit(1).string_col)

# execute doesn't get called
execute_spy.assert_not_called()

# pyarrow does get called
to_pyarrow_spy.assert_called_once()
2 changes: 1 addition & 1 deletion ibis/expr/types/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def _to_rich_scalar(
) -> Pretty:
value = format_values(
expr.type(),
[expr.execute()],
[expr.to_pyarrow().as_py()],
max_length=max_length or ibis.options.repr.interactive.max_length,
max_string=max_string or ibis.options.repr.interactive.max_string,
max_depth=max_depth or ibis.options.repr.interactive.max_depth,
Expand Down

0 comments on commit 05172cd

Please sign in to comment.