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

feat(ir): support showing variable names used to create an expression in repr() #8630

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

kszucs
Copy link
Member

@kszucs kszucs commented Mar 12, 2024

For the following code:

import ibis

alltypes = ibis.table(...)

filtered = alltypes[alltypes.f > 0]
ordered = filtered.order_by("f")
projected = ordered[["a", "b", "f"]]

expr = projected.a + projected.b

ibis.options.repr.show_variables = True
repr(expr)

instead of showing

r0 := UnboundTable: alltypes
  a int8
  b int16
  c int32
  d int64
  e float32
  f float64
  g string
  h boolean
  i timestamp
  j date
  k time

r1 := Filter[r0]
  r0.f > 0

r2 := Sort[r1]
  asc r1.f

r3 := Project[r2]
  a: r2.a
  b: r2.b
  f: r2.f

Add(a, b): r3.a + r3.b

now we can render the expression representation as

alltypes := UnboundTable: alltypes
   a int8
   b int16
   c int32
   d int64
   e float32
   f float64
   g string
   h boolean
   i timestamp
   j date
   k time

 filtered := Filter[alltypes]
   alltypes.f > 0

 ordered := Sort[filtered]
   asc filtered.f

 projected := Project[ordered]
   a: ordered.a
   b: ordered.b
   f: ordered.f

 Add(a, b): projected.a + projected.b

This removes one level of indirection when we inspect an expression. Also not just tables but value nodes assigned to local variables are shown.

Note that it has its limitation based on where repr() is called, but ibis.expr.format.pretty now accepts a scope argument where the variable names can be passed.

@kszucs kszucs changed the title feat(ir): support showing variable names used to create an expression in repr() feat(ir): support showing variable names used to create an expression in repr() Mar 12, 2024
ibis/expr/types/core.py Outdated Show resolved Hide resolved
@kszucs kszucs force-pushed the repr-variables branch 2 times, most recently from b3dde3d to 2bd5c6f Compare March 12, 2024 16:34
@kszucs
Copy link
Member Author

kszucs commented Mar 12, 2024

Requires a follow-up ticket to document this.

Copy link
Member

@cpcloud cpcloud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, but doesn't really work with IPython at the moment.

I'm a bit wary of testing this until we work out more of the kinks given how niche the feature is.

ibis/expr/tests/test_format.py Show resolved Hide resolved
ibis/backends/tests/test_interactive.py Outdated Show resolved Hide resolved
ibis/expr/types/core.py Outdated Show resolved Hide resolved
ibis/expr/format.py Outdated Show resolved Hide resolved
@cpcloud cpcloud added the developer-tools Tools related to ibis development label Mar 13, 2024
@cpcloud cpcloud added this to the 9.0 milestone Mar 13, 2024
@cpcloud cpcloud merged commit 220085e into ibis-project:main Mar 13, 2024
80 checks passed
@kszucs kszucs deleted the repr-variables branch March 19, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-tools Tools related to ibis development
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants