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(api): support deferred expressions in ibis.date/ibis.time/ibis.timestamp #7204

Merged
merged 6 commits into from
Sep 27, 2023

Conversation

jcrist
Copy link
Member

@jcrist jcrist commented Sep 22, 2023

This PR does a few things:

  • Adds full support for deferred expressions passed to ibis.date/ibis.time/ibis.timestamp
  • Adds a new deferrable decorator (non-public) for wrapping top-level expr functions and making them work with deferred arguments.
  • Improves the docstrings of ibis.date/ibis.time/ibis.timestamp
  • Improves the type-signatures of ibis.date/ibis.time/ibis.timestamp. In particular, now mypy/pyright will complain if you don't pass in all components required or the components are the incorrect type. It also fixes the return type to indicate it's not always a scalar.

Fixes #4534.

@jcrist
Copy link
Member Author

jcrist commented Sep 22, 2023

A quick demo:

In [1]: import ibis

In [2]: ibis.options.interactive = True

In [3]: from ibis import _

In [4]: t = ibis.memtable({"h": [1, 4], "m": [2, 5], "s": [3, 6]})

In [5]: t.mutate(time=ibis.time(_.h, _.m, _.s))  # time column from components
Out[5]: 
┏━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━┓
┃ hmstime     ┃
┡━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━┩
│ int64int64int64time     │
├───────┼───────┼───────┼──────────┤
│     12301:02:03 │
│     45604:05:06 │
└───────┴───────┴───────┴──────────┘

In [6]: t.mutate(timestamp=ibis.timestamp(2023, 1, 2, _.h, _.m, _.s))  # timestamp column from components
┏━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┓
┃ hmstimestamp           ┃
┡━━━━━━━╇━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━┩
│ int64int64int64timestamp           │
├───────┼───────┼───────┼─────────────────────┤
│     1232023-01-02 01:02:03 │
│     4562023-01-02 04:05:06 │
└───────┴───────┴───────┴─────────────────────┘

Copy link
Member

@gforsyth gforsyth left a comment

Choose a reason for hiding this comment

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

Very minor nit -- definitely not blocking.

This is very nice and the function argument restrictions are well done.

ibis/expr/api.py Outdated Show resolved Hide resolved
@cpcloud cpcloud added this to the 7.0 milestone Sep 25, 2023
@cpcloud cpcloud added feature Features or general enhancements ux User experience related issues timestamps Issues related to the timestamp API labels Sep 25, 2023
@cpcloud
Copy link
Member

cpcloud commented Sep 27, 2023

Went ahead and committed the suggested error message, so we can merge this!

@cpcloud
Copy link
Member

cpcloud commented Sep 27, 2023

Oh bother, pre-commit 😒

@cpcloud cpcloud enabled auto-merge (rebase) September 27, 2023 16:28
@cpcloud cpcloud merged commit 86b4c6f into ibis-project:master Sep 27, 2023
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Features or general enhancements timestamps Issues related to the timestamp API ux User experience related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add support for ibis.date(y, m, d) using deferred
3 participants