Skip to content

feat: Implement dt.{replace,convert}_time_zone, dt.timestamp, join_asof, windowed first/last; fix over and null edge cases - #149

Merged
jonasdedden merged 4 commits into
narwhals-dev:mainfrom
jonasdedden:feat/dt-tz-join-asof-first-last
Nov 15, 2026
Merged

jonasdedden merged 4 commits into
narwhals-dev:mainfrom
jonasdedden:feat/dt-tz-join-asof-first-last

Conversation

@jonasdedden

@jonasdedden jonasdedden commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Wires up functionality Daft already has natively, plus a few small semantic fixes.

New:

  • dt.replace_time_zone / dt.convert_time_zone via F.replace_time_zone / F.convert_time_zone. Naive input to convert_time_zone is treated as UTC, like Polars; from_timezone is ignored for tz-aware input.
  • dt.timestamp via F.to_unix_epoch. Non-temporal input raises TypeError("Input should be either of Date or Datetime type"), like the other backends; the check resolves the dtype against the frame at plan time.
  • LazyFrame.join_asof via DataFrame.join_asof. Its key, by and suffix handling already matches Polars, so it's a pass-through.
  • first / last within over (and broadcast in with_columns) via F.first_value / F.last_value. These need an explicit unbounded rows_between frame. As a plain aggregation (select, group_by) they raise NotImplementedError, because Daft has no ordered aggregate.

Fixes:

  • any / all / n_unique inside over: Daft only accepts a bare aggregation as the window expression, so coalesce / + now wrap the windowed aggregations rather than the other way round.
  • is_in with nulls in other: Daft returns null for every non-match once other contains a null.
  • Unary - uses F.negate.
  • str.slice: a negative offset reaching before the start errored in Daft. It's now clipped, with an explicit length shortened by the overhang, as Polars does. Empty results are "" instead of null.
  • str.strip_chars(characters) reuses the escaped character-class regex from strip_chars_{start,end}, and an empty characters is a no-op.
  • list.unique accepts maintain_order. True raises, because list_distinct drops nulls and they are re-appended at the end.
  • with_row_index(order_by=...) puts nulls first and stays UInt64 (row_number() - 1 used to promote to Float64).

Requires #147 (pin update) first, and is independent of #148. Both PRs touch the exclusion list in run_tests.py, so whichever merges second needs a trivial rebase. On top of #147: 309 → 244 failures on the full suite, no new failures, and 28 names dropped from run_tests.py.

Update (performance review): is_in now skips the null guard (when) unless the filtered list is empty. Daft already keeps null input as null when the list has no null, so is_in now runs at the speed of Daft's own is_in. In a 5M-row benchmark, every other new or changed expression here also runs at native speed:

  • windowed first/last vs first_value;
  • any/all/n_unique over windows;
  • time zones and timestamp;
  • join_asof;
  • unary -.

Note

I used Claude (Opus 5.5) to help with these changes and this description.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 28cd8cc7-2d14-478d-829e-dc41c50cdfd9
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@jonasdedden
jonasdedden force-pushed the feat/dt-tz-join-asof-first-last branch from 3b75add to 5e59db9 Compare November 15, 2026 14:12
jonasdedden added a commit to jonasdedden/narwhals-daft that referenced this pull request Nov 15, 2026
The previous floor (0.5.18) was stale: main already needs 0.7.13 (median,
percentile, concat_ws, struct literals) and the windowed first/last and
join_asof(strategy='nearest') in narwhals-dev#149 need 0.7.15.
@jonasdedden
jonasdedden force-pushed the feat/dt-tz-join-asof-first-last branch from 5e59db9 to 33c5fc0 Compare November 15, 2026 14:34
@jonasdedden
jonasdedden force-pushed the feat/dt-tz-join-asof-first-last branch from 31b30c2 to 7a5d727 Compare November 15, 2026 15:07
@jonasdedden
jonasdedden merged commit aeba19e into narwhals-dev:main Nov 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants