Skip to content

Commit

Permalink
feat: add _repr_html_ for expressions to print as tables in ipython
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Feb 25, 2022
1 parent 350a9b8 commit cd6fa4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ibis/expr/types/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from public import public

import ibis
import ibis.common.exceptions as com

from .core import Expr
Expand Down Expand Up @@ -77,6 +78,9 @@ def to_projection(self):
table = TableExpr(roots[0])
return table.projection([self])

def _repr_html_(self) -> str | None:
return None


@public
class ColumnExpr(ValueExpr):
Expand All @@ -103,6 +107,12 @@ def to_projection(self):
table = TableExpr(roots[0])
return table.projection([self])

def _repr_html_(self) -> str | None:
if not ibis.options.interactive:
return None

return self.execute().to_frame()._repr_html_()


@public
class AnyValue(ValueExpr):
Expand Down
7 changes: 7 additions & 0 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
from public import public

import ibis
import ibis.common.exceptions as com
import ibis.util as util

Expand Down Expand Up @@ -45,6 +46,12 @@ def _assert_valid(self, exprs):
def __contains__(self, name):
return name in self.schema()

def _repr_html_(self) -> str | None:
if not ibis.options.interactive:
return None

return self.execute()._repr_html_()

def __getitem__(self, what):
from .analytic import AnalyticExpr
from .generic import ColumnExpr
Expand Down

0 comments on commit cd6fa4e

Please sign in to comment.