Skip to content

[Enh]: support other units in expr.dt.offset_by for ibis backend #3681

@CangyuanLi

Description

@CangyuanLi

We would like to learn about your use case. For example, if this feature is needed to adopt Narwhals in an open source project, could you please enter the link to it below?

Thanks for the great library! We use narwhals at $WORK to write backend-agnostic code. One of our backends is Snowflake (via the Ibis backend).

Please describe the purpose of the new feature or describe the problem to solve.

Would it be possible to enable offsetting by other units (like month) in .dt.offset_by for the ibis backend? It appears that all of the pieces to support it are already there. For example, in the core function that does the interval

def timedelta_to_ibis_interval(td: timedelta) -> ibis.expr.types.temporal.IntervalScalar:
    return ibis.interval(days=td.days, seconds=td.seconds, microseconds=td.microseconds)

it directly uses ibis.interval, which supports nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days, weeks, months, quarters, and years. Would it just be a matter of relaxing this check (

if unit in {"y", "q", "mo", "d", "ns"}:
)?

if unit in {"y", "q", "mo", "d", "ns"}:
      msg = f"Offsetting by {unit} is not yet supported for ibis."

Suggest a solution if possible.

Relax the check

if unit in {"y", "q", "mo", "d", "ns"}:

If you have tried alternatives, please describe them below.

Creating a custom .dt.offset_by function

Additional information that may help us understand your needs.

I would be willing to contribute this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestibisIssue is related to ibis backend

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions