Skip to content

Commit 7e0d03e

Browse files
committed
fix(python): satisfy ruff and ty after rebase
Use datetime.UTC, annotate _time_zone_scan, type the datetime unit mapping for _dtype.timestamp, and build expected frames with pl.DataFrame so ty can see a DataFrame rather than DataFrame | Series. Signed-off-by: Claude <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E92wUoS3LaqWVJmmS7vKVq
1 parent d6c0b1f commit 7e0d03e

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎vortex-python/python/vortex/polars_.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import json
55
import operator
66
from collections.abc import Callable
7-
from typing import Any, cast
7+
from typing import Any, Literal, cast
88

99
import polars as pl
1010

@@ -199,7 +199,12 @@ def _polars_to_vortex(expr: dict[str, Any]) -> ve.Expr:
199199

200200
def _datetime_literal(data: list[Any]) -> ve.Expr:
201201
value, unit, tz = data
202-
units = {"Nanoseconds": "ns", "Microseconds": "us", "Milliseconds": "ms", "Seconds": "s"}
202+
units: dict[str, Literal["s", "ms", "us", "ns"]] = {
203+
"Nanoseconds": "ns",
204+
"Microseconds": "us",
205+
"Milliseconds": "ms",
206+
"Seconds": "s",
207+
}
203208
if unit not in units:
204209
raise NotImplementedError(f"Unsupported Polars date time unit: {unit}")
205210
if isinstance(tz, dict):

‎vortex-python/test/test_polars_.py‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
import math
55
import os
6-
from datetime import date, datetime, time, timezone
6+
from datetime import UTC, date, datetime, time
77
from decimal import Decimal
8-
from datetime import datetime, timezone
98
from zoneinfo import ZoneInfo
109

1110
import polars as pl
@@ -213,15 +212,15 @@ def test_datetime_predicate_pushdown(tmp_path):
213212
{
214213
"id": [0, 1, 2],
215214
"value": pa.array(
216-
[datetime(2026, 9, day, tzinfo=timezone.utc) for day in [16, 17, 18]],
215+
[datetime(2026, 9, day, tzinfo=UTC) for day in [16, 17, 18]],
217216
type=pa.timestamp("us", tz="UTC"),
218217
),
219218
}
220219
)
221220
path = tmp_path / "datetimes.vortex"
222221
vx.io.write(vx.array(table), str(path))
223-
predicate = pl.col("value") >= datetime(2026, 9, 17, tzinfo=timezone.utc)
224-
expected = pl.from_arrow(table).lazy().filter(predicate).collect()
222+
predicate = pl.col("value") >= datetime(2026, 9, 17, tzinfo=UTC)
223+
expected = pl.DataFrame(table).lazy().filter(predicate).collect()
225224
result = vx.open(str(path)).to_polars().filter(predicate).collect()
226225
assert_frame_equal(result, expected)
227226
assert result["id"].to_list() == [1, 2]
@@ -283,9 +282,7 @@ def test_replace_time_zone_policy_column(tmp_path, fold, expected):
283282

284283

285284
def test_replace_time_zone_non_existent_null(tmp_path):
286-
values = pa.array(
287-
[datetime(2024, 3, 10, 2, 30), datetime(2024, 3, 10, 3, 30)], type=pa.timestamp("us")
288-
)
285+
values = pa.array([datetime(2024, 3, 10, 2, 30), datetime(2024, 3, 10, 3, 30)], type=pa.timestamp("us"))
289286
reference, frame = _time_zone_scan(tmp_path, values)
290287
expression = pl.col("dt").dt.replace_time_zone("America/New_York", non_existent="null")
291288
threshold = datetime(2024, 3, 10, 3, 30, tzinfo=ZoneInfo("America/New_York"))
@@ -307,9 +304,7 @@ def test_replace_time_zone_raises(tmp_path, value):
307304

308305

309306
def test_replace_time_zone_maps_to_native_expression():
310-
expression = pl.col("dt").dt.replace_time_zone(
311-
"America/New_York", ambiguous=pl.col("policy"), non_existent="null"
312-
)
307+
expression = pl.col("dt").dt.replace_time_zone("America/New_York", ambiguous=pl.col("policy"), non_existent="null")
313308
expected = ve.replace_time_zone(
314309
ve.column("dt"), "America/New_York", ambiguous=ve.column("policy"), non_existent="null"
315310
)
@@ -328,11 +323,11 @@ def test_replace_time_zone_same_zone_during_fold(tmp_path):
328323
assert actual["id"].to_list() == [0]
329324

330325

331-
def _time_zone_scan(tmp_path, values, policy=None):
326+
def _time_zone_scan(tmp_path, values, policy=None) -> tuple[pl.LazyFrame, pl.LazyFrame]:
332327
columns = {"id": pa.array(range(len(values))), "dt": values}
333328
if policy is not None:
334329
columns["policy"] = pa.array(policy)
335330
path = tmp_path / "timezones.vortex"
336331
table = pa.table(columns)
337332
vx.io.write(vx.array(table), str(path))
338-
return pl.from_arrow(table).lazy(), vx.open(str(path)).to_polars()
333+
return pl.DataFrame(table).lazy(), vx.open(str(path)).to_polars()

0 commit comments

Comments
 (0)