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

bug(timestamps): ibis.range doesn't accept ibis.timestamp objects (ibis expressions) #9557

Closed
1 task done
cpcloud opened this issue Jul 12, 2024 · 2 comments · Fixed by #9659
Closed
1 task done
Assignees
Labels
bug Incorrect behavior inside of ibis feature Features or general enhancements timestamps Issues related to the timestamp API
Milestone

Comments

@cpcloud
Copy link
Member

cpcloud commented Jul 12, 2024

What happened?

In [1]: from ibis.interactive import *

In [2]: expr = ibis.range(ibis.now() - ibis.interval(days=1), ibis.now(), ibis.interval(seconds=1))

Fails with

TypeError: Unable to normalize <class 'ibis.expr.types.temporal.TimestampScalar'> to timestamp

Looks like we expect timestamp-like inputs to range to be Python literals, but we should allow arbitrary timestamp-typed expressions.

What version of ibis are you using?

main

What backend(s) are you using, if any?

DuckDB

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@cpcloud cpcloud added the bug Incorrect behavior inside of ibis label Jul 12, 2024
@cpcloud cpcloud added feature Features or general enhancements timestamps Issues related to the timestamp API labels Jul 12, 2024
@lostmygithubaccount
Copy link
Member

I didn't know you could do this and wrote:

import ibis
import ibis.expr.datatypes as dt

ibis.options.interactive = True

ROWS = 1000
TIMESCALE = "m"

t = (
    ibis.range(ROWS)
    .unnest()
    .name("index")
    .as_table()
    .mutate(timestamp=ibis.now(), _tmp=ibis._["index"].cast(dt.Interval(TIMESCALE)))
    .mutate(timestamp=((ibis._["timestamp"] - ibis._["_tmp"]).truncate(TIMESCALE)))
    .drop("index", "_tmp")
)
t

much cleaner:

import ibis

from datetime import datetime, timedelta

ibis.options.interactive = True

now = datetime.now()

t = (
    ibis.range(now - timedelta(days=2), now, step=ibis.interval(minutes=1))
    .unnest()
    .name("timestamp")
    .as_table()
)
t

+1 on allowing ibis.now() and other things

@cpcloud cpcloud self-assigned this Jul 22, 2024
@cpcloud
Copy link
Member Author

cpcloud commented Jul 22, 2024

PR incoming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior inside of ibis feature Features or general enhancements timestamps Issues related to the timestamp API
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants