Skip to content

Commit 9199450

Browse files
committed
fix: use col() references in tests and fix formatting
1 parent 97f83de commit 9199450

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

daft/functions/datetime.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,9 @@ def make_timestamp_ltz(
13851385
Examples:
13861386
>>> import daft
13871387
>>> from daft.functions import make_timestamp_ltz
1388-
>>> make_timestamp_ltz(daft.col("y"), daft.col("m"), daft.col("d"), daft.col("h"), daft.col("mi"), daft.col("s"))
1388+
>>> make_timestamp_ltz(
1389+
... daft.col("y"), daft.col("m"), daft.col("d"), daft.col("h"), daft.col("mi"), daft.col("s")
1390+
... )
13891391
make_timestamp_ltz(col(y), col(m), col(d), col(h), col(mi), col(s))
13901392
"""
13911393
year = Expression._to_expression(year)

tests/dataframe/test_temporals.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -827,14 +827,14 @@ def test_current_temporal_sql() -> None:
827827

828828
def test_make_date() -> None:
829829
df = daft.from_pydict({"y": [2021, 2020, 2000], "m": [1, 2, 12], "d": [15, 29, 31]})
830-
df = df.with_column("dt", make_date("y", "m", "d"))
830+
df = df.with_column("dt", make_date(col("y"), col("m"), col("d")))
831831
result = df.to_pydict()
832832
assert result["dt"] == [date(2021, 1, 15), date(2020, 2, 29), date(2000, 12, 31)]
833833

834834

835835
def test_make_date_invalid() -> None:
836836
df = daft.from_pydict({"y": [2021, 2021], "m": [2, 13], "d": [30, 1]})
837-
df = df.with_column("dt", make_date("y", "m", "d"))
837+
df = df.with_column("dt", make_date(col("y"), col("m"), col("d")))
838838
result = df.to_pydict()
839839
assert result["dt"] == [None, None]
840840

@@ -843,20 +843,16 @@ def test_make_date_invalid() -> None:
843843

844844

845845
def test_make_timestamp() -> None:
846-
df = daft.from_pydict(
847-
{"y": [2021], "m": [1], "d": [1], "h": [12], "mi": [30], "s": [45.0]}
848-
)
849-
df = df.with_column("ts", make_timestamp("y", "m", "d", "h", "mi", "s"))
846+
df = daft.from_pydict({"y": [2021], "m": [1], "d": [1], "h": [12], "mi": [30], "s": [45.0]})
847+
df = df.with_column("ts", make_timestamp(col("y"), col("m"), col("d"), col("h"), col("mi"), col("s")))
850848
result = df.to_pydict()
851849
assert result["ts"] == [datetime(2021, 1, 1, 12, 30, 45)]
852850

853851

854852
def test_make_timestamp_with_timezone() -> None:
855-
df = daft.from_pydict(
856-
{"y": [2021], "m": [1], "d": [1], "h": [12], "mi": [0], "s": [0.0]}
857-
)
853+
df = daft.from_pydict({"y": [2021], "m": [1], "d": [1], "h": [12], "mi": [0], "s": [0.0]})
858854
df = df.with_column(
859-
"ts", make_timestamp("y", "m", "d", "h", "mi", "s", timezone="UTC")
855+
"ts", make_timestamp(col("y"), col("m"), col("d"), col("h"), col("mi"), col("s"), timezone="UTC")
860856
)
861857
result = df.to_pydict()
862858
assert result["ts"] == [datetime(2021, 1, 1, 12, 0, 0, tzinfo=timezone.utc)]
@@ -866,20 +862,16 @@ def test_make_timestamp_with_timezone() -> None:
866862

867863

868864
def test_make_timestamp_ltz() -> None:
869-
df = daft.from_pydict(
870-
{"y": [2021], "m": [1], "d": [1], "h": [12], "mi": [0], "s": [0.0]}
871-
)
872-
df = df.with_column("ts", make_timestamp_ltz("y", "m", "d", "h", "mi", "s"))
865+
df = daft.from_pydict({"y": [2021], "m": [1], "d": [1], "h": [12], "mi": [0], "s": [0.0]})
866+
df = df.with_column("ts", make_timestamp_ltz(col("y"), col("m"), col("d"), col("h"), col("mi"), col("s")))
873867
result = df.to_pydict()
874868
assert result["ts"] == [datetime(2021, 1, 1, 12, 0, 0, tzinfo=timezone.utc)]
875869

876870

877871
def test_make_timestamp_ltz_with_timezone() -> None:
878-
df = daft.from_pydict(
879-
{"y": [2021], "m": [1], "d": [1], "h": [12], "mi": [0], "s": [0.0]}
880-
)
872+
df = daft.from_pydict({"y": [2021], "m": [1], "d": [1], "h": [12], "mi": [0], "s": [0.0]})
881873
df = df.with_column(
882-
"ts", make_timestamp_ltz("y", "m", "d", "h", "mi", "s", timezone="US/Eastern")
874+
"ts", make_timestamp_ltz(col("y"), col("m"), col("d"), col("h"), col("mi"), col("s"), timezone="US/Eastern")
883875
)
884876
result = df.to_pydict()
885877
# 12:00 EST = 17:00 UTC
@@ -890,10 +882,8 @@ def test_make_timestamp_ltz_with_timezone() -> None:
890882

891883

892884
def test_last_day() -> None:
893-
df = daft.from_pydict(
894-
{"dt": [date(2021, 1, 15), date(2021, 2, 10), date(2020, 2, 10), date(2021, 4, 1)]}
895-
)
896-
df = df.with_column("last", last_day("dt"))
885+
df = daft.from_pydict({"dt": [date(2021, 1, 15), date(2021, 2, 10), date(2020, 2, 10), date(2021, 4, 1)]})
886+
df = df.with_column("last", last_day(col("dt")))
897887
result = df.to_pydict()
898888
assert result["last"] == [
899889
date(2021, 1, 31),
@@ -911,7 +901,7 @@ def test_next_day() -> None:
911901
df = daft.from_pydict({"dt": [date(2021, 1, 1), date(2021, 1, 1), date(2021, 1, 1)]})
912902
results = {}
913903
for dow in ["Monday", "Friday", "Sunday"]:
914-
tmp = df.with_column("nd", next_day("dt", dow))
904+
tmp = df.with_column("nd", next_day(col("dt"), dow))
915905
results[dow] = tmp.to_pydict()["nd"]
916906
assert results["Monday"] == [date(2021, 1, 4)] * 3 # next Mon
917907
assert results["Friday"] == [date(2021, 1, 8)] * 3 # next Fri (not same day)

0 commit comments

Comments
 (0)