From 1eba8bef192e93cc97ed8b49b8c60f2bc8e118f4 Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Tue, 17 Jan 2023 18:04:58 -0500 Subject: [PATCH] feat(snowflake): implement `TimestampFromYMDHMS` --- ibis/backends/snowflake/registry.py | 2 +- ibis/backends/tests/test_temporal.py | 16 +++++++++++++++- ibis/expr/api.py | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ibis/backends/snowflake/registry.py b/ibis/backends/snowflake/registry.py index 005fdfa5772a..afec3990ce4b 100644 --- a/ibis/backends/snowflake/registry.py +++ b/ibis/backends/snowflake/registry.py @@ -233,6 +233,7 @@ def _map(_, op): ), 1, ), + ops.TimestampFromYMDHMS: fixed_arity(sa.func.timestamp_from_parts, 6), } ) @@ -256,7 +257,6 @@ def _map(_, op): ops.IntervalFromInteger, ops.TimestampDiff, ops.TimestampFromUNIX, - ops.TimestampFromYMDHMS, } operation_registry = { diff --git a/ibis/backends/tests/test_temporal.py b/ibis/backends/tests/test_temporal.py index 3a3d7e8d5d09..355786cd48fe 100644 --- a/ibis/backends/tests/test_temporal.py +++ b/ibis/backends/tests/test_temporal.py @@ -781,7 +781,7 @@ def test_date_literal(con): assert result.strftime('%Y-%m-%d') == '2022-02-04' -@pytest.mark.notimpl(["pandas", "datafusion", "mysql", "dask", "pyspark", "snowflake"]) +@pytest.mark.notimpl(["pandas", "datafusion", "mysql", "dask", "pyspark"]) @pytest.mark.notyet(["clickhouse", "impala"]) def test_timestamp_literal(con): expr = ibis.timestamp(2022, 2, 4, 16, 20, 0) @@ -824,6 +824,20 @@ def test_date_column_from_ymd(con, alltypes, df): tm.assert_series_equal(golden, result.timestamp_col) +@pytest.mark.notimpl(["pandas", "datafusion", "mysql", "dask", "pyspark"]) +@pytest.mark.notyet(["clickhouse", "impala"]) +def test_timestamp_column_from_ymdhms(con, alltypes, df): + c = alltypes.timestamp_col + expr = ibis.timestamp( + c.year(), c.month(), c.day(), c.hour(), c.minute(), c.second() + ) + tbl = alltypes[expr.name('timestamp_col')] + result = con.execute(tbl) + + golden = df.timestamp_col.dt.floor("s").astype('datetime64[ns]') + tm.assert_series_equal(golden, result.timestamp_col) + + @pytest.mark.notimpl(["datafusion", "impala"]) def test_date_scalar_from_iso(con): expr = ibis.literal('2022-02-24') diff --git a/ibis/expr/api.py b/ibis/expr/api.py index 8ac1a5a76d86..ee333384113f 100644 --- a/ibis/expr/api.py +++ b/ibis/expr/api.py @@ -585,6 +585,7 @@ def timestamp( @timestamp.register(np.floating) @timestamp.register(int) @timestamp.register(float) +@timestamp.register(ir.IntegerValue) def _timestamp_from_ymdhms( value, *args, timezone: str | None = None ) -> ir.TimestampScalar: