Skip to content

Commit ee6d58a

Browse files
cpcloudgforsyth
authored andcommitted
fix(ux): remove extra trailing newline in expression repr
1 parent 133cf6f commit ee6d58a

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

ibis/expr/types/core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ibis.common.grounds import Immutable
1515
from ibis.config import _default_backend, options
1616
from ibis.util import experimental
17+
from rich.jupyter import JupyterMixin
1718

1819
if TYPE_CHECKING:
1920
import pyarrow as pa
@@ -23,6 +24,15 @@
2324
from ibis.expr.typing import TimeContext
2425

2526

27+
class _FixedTextJupyterMixin(JupyterMixin):
28+
"""JupyterMixin adds a spurious newline to text, this fixes the issue."""
29+
30+
def _repr_mimebundle_(self, *args, **kwargs):
31+
bundle = super()._repr_mimebundle_(*args, **kwargs)
32+
bundle["text/plain"] = bundle["text/plain"].rstrip()
33+
return bundle
34+
35+
2636
# TODO(kszucs): consider to subclass from Annotable with a single _arg field
2737
@public
2838
class Expr(Immutable):

ibis/expr/types/generic.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
from typing import TYPE_CHECKING, Any, Iterable, Literal, Sequence
44

55
from public import public
6-
from rich.jupyter import JupyterMixin
76

87
import ibis
98
import ibis.common.exceptions as com
109
import ibis.expr.datatypes as dt
1110
import ibis.expr.operations as ops
1211
from ibis import util
1312
from ibis.common.grounds import Singleton
14-
from ibis.expr.types.core import Expr, _binop
13+
from ibis.expr.types.core import Expr, _binop, _FixedTextJupyterMixin
1514

1615
if TYPE_CHECKING:
1716
import ibis.expr.types as ir
@@ -570,7 +569,7 @@ def _repr_html_(self) -> str | None:
570569

571570

572571
@public
573-
class Column(Value, JupyterMixin):
572+
class Column(Value, _FixedTextJupyterMixin):
574573
# Higher than numpy & dask objects
575574
__array_priority__ = 20
576575

ibis/expr/types/relations.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
)
1919

2020
from public import public
21-
from rich.jupyter import JupyterMixin
2221

2322
import ibis
2423
import ibis.common.exceptions as com
@@ -27,7 +26,7 @@
2726
from ibis import util
2827
from ibis.expr.deferred import Deferred
2928
from ibis.expr.selectors import Selector
30-
from ibis.expr.types.core import Expr
29+
from ibis.expr.types.core import Expr, _FixedTextJupyterMixin
3130

3231
if TYPE_CHECKING:
3332
import ibis.expr.schema as sch
@@ -85,7 +84,7 @@ def f( # noqa: D417
8584

8685

8786
@public
88-
class Table(Expr, JupyterMixin):
87+
class Table(Expr, _FixedTextJupyterMixin):
8988
# Higher than numpy & dask objects
9089
__array_priority__ = 20
9190

0 commit comments

Comments
 (0)