Skip to content

Commit cba5990

Browse files
timsaucerclaude
andcommitted
Add unit tests for make_time, current_timestamp, and date_format
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4878280 commit cba5990

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

python/tests/test_functions.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,39 @@ def test_today_alias_matches_current_date(df):
11071107
assert result.column(0) == result.column(1)
11081108

11091109

1110+
def test_current_timestamp_alias_matches_now(df):
1111+
result = df.select(
1112+
f.now().alias("now"),
1113+
f.current_timestamp().alias("current_timestamp"),
1114+
).collect()[0]
1115+
1116+
assert result.column(0) == result.column(1)
1117+
1118+
1119+
def test_date_format_alias_matches_to_char(df):
1120+
result = df.select(
1121+
f.to_char(
1122+
f.to_timestamp(literal("2021-01-01T00:00:00")), literal("%Y/%m/%d")
1123+
).alias("to_char"),
1124+
f.date_format(
1125+
f.to_timestamp(literal("2021-01-01T00:00:00")), literal("%Y/%m/%d")
1126+
).alias("date_format"),
1127+
).collect()[0]
1128+
1129+
assert result.column(0) == result.column(1)
1130+
assert result.column(0)[0].as_py() == "2021/01/01"
1131+
1132+
1133+
def test_make_time(df):
1134+
ctx = SessionContext()
1135+
df_time = ctx.from_pydict({"h": [12], "m": [30], "s": [0]})
1136+
result = df_time.select(
1137+
f.make_time(column("h"), column("m"), column("s")).alias("t")
1138+
).collect()[0]
1139+
1140+
assert result.column(0)[0].as_py() == time(12, 30)
1141+
1142+
11101143
def test_arrow_cast(df):
11111144
df = df.select(
11121145
# we use `string_literal` to return utf8 instead of `literal` which returns

0 commit comments

Comments
 (0)