Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ibis/backends/datafusion/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
from pytest import param

import ibis
from ibis.backends.datafusion.tests.conftest import BackendTest

pd = pytest.importorskip("pandas")
pa = pytest.importorskip("pyarrow")


@pytest.mark.parametrize(
Expand Down Expand Up @@ -36,3 +40,30 @@
def test_time_extract_literal(con, func, expected):
value = ibis.time("14:48:05.359")
assert con.execute(func(value).name("tmp")) == expected


@pytest.mark.parametrize(
"pattern",
[
"%Y-%m-%d",
"%Y:%m:%d",
"%Y%m%d",
"%d-%m-%Y",
"%Y-%b-%d",
"%Y-%B-%d",
"%Y-%B-%d-%a",
"%F",
"%Y:%m:%d:%H:%M:%S",
],
)
def test_strftime(con, pattern):
df = pd.DataFrame({"time_col": pa.array([18506, 18507, 18508, 18509], pa.date32())})

t = ibis.memtable(df)

name = "formatted"
expr = t.time_col.strftime(pattern).name(name)
expected = df.time_col.dt.strftime(pattern).rename(name)

result = con.execute(expr)
BackendTest.assert_series_equal(result, expected)
4 changes: 3 additions & 1 deletion ibis/backends/sql/compilers/datafusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class DataFusionCompiler(SQLGlotCompiler):
ops.CountDistinctStar,
ops.DateDelta,
ops.RowID,
ops.Strftime,
ops.TimeDelta,
ops.TimestampBucket,
ops.TimestampDelta,
Expand Down Expand Up @@ -629,5 +628,8 @@ def visit_ApproxQuantile(self, op, *, arg, quantile, where):
def visit_ApproxQuantile(self, op, *, arg, quantile, where):
return self.agg.approx_percentile_cont(arg, quantile, where=where)

def visit_Strftime(self, op, *, arg, format_str):
return self.f.date_format(arg, format_str)


compiler = DataFusionCompiler()
4 changes: 1 addition & 3 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,9 +1041,7 @@ def test_interval_add_cast_column(backend, alltypes, df):
),
],
)
@pytest.mark.notimpl(
["datafusion", "druid", "exasol"], raises=com.OperationNotDefinedError
)
@pytest.mark.notimpl(["druid", "exasol"], raises=com.OperationNotDefinedError)
def test_strftime(backend, alltypes, df, expr_fn, pandas_pattern):
expr = expr_fn(alltypes)
expected = df.timestamp_col.dt.strftime(pandas_pattern).rename("formatted")
Expand Down