From 8b5b177e3f8044f6334b70726a5892341f829b6d Mon Sep 17 00:00:00 2001 From: Sarah Yurick Date: Wed, 12 Oct 2022 13:44:49 -0700 Subject: [PATCH 1/3] check np.timedelta64 case --- dask_sql/physical/rex/core/call.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dask_sql/physical/rex/core/call.py b/dask_sql/physical/rex/core/call.py index c0b364d89..b65956254 100644 --- a/dask_sql/physical/rex/core/call.py +++ b/dask_sql/physical/rex/core/call.py @@ -46,6 +46,8 @@ def as_timelike(op): return np.datetime64(op) elif pd.api.types.is_datetime64_dtype(op): return op + elif isinstance(op, np.timedelta64): + return op else: raise ValueError(f"Don't know how to make {type(op)} timelike") From 198b51045d83e47680de2ebfc52d230a739b540f Mon Sep 17 00:00:00 2001 From: Sarah Yurick Date: Thu, 13 Oct 2022 10:08:54 -0700 Subject: [PATCH 2/3] add test --- tests/integration/test_rex.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_rex.py b/tests/integration/test_rex.py index 00153fc43..655ff69de 100644 --- a/tests/integration/test_rex.py +++ b/tests/integration/test_rex.py @@ -59,7 +59,6 @@ def test_intervals(c): """SELECT INTERVAL '3' DAY as "IN" """ ) - expected_df = pd.DataFrame( { "IN": [pd.to_timedelta("3d")], @@ -67,6 +66,24 @@ def test_intervals(c): ) assert_eq(df, expected_df) + date1 = datetime(2021, 10, 3, 15, 53, 42, 47) + date2 = datetime(2021, 2, 28, 15, 53, 42, 47) + dates = dd.from_pandas(pd.DataFrame({"d": [date1, date2]}), npartitions=1) + c.register_dask_table(dates, "dates") + df = c.sql( + """SELECT d + INTERVAL '5 days' AS "Plus_5_days" FROM dates + """ + ) + expected_df = pd.DataFrame( + { + "Plus_5_days": [ + datetime(2021, 10, 8, 15, 53, 42, 47), + datetime(2021, 3, 5, 15, 53, 42, 47), + ] + } + ) + assert_eq(df, expected_df) + def test_literals(c): df = c.sql( From 072b5a023d7350e8f1ea6358c0f3852ed71f32c3 Mon Sep 17 00:00:00 2001 From: Sarah Yurick <53962159+sarahyurick@users.noreply.github.com> Date: Thu, 13 Oct 2022 10:14:59 -0700 Subject: [PATCH 3/3] Update dask_sql/physical/rex/core/call.py Co-authored-by: Ayush Dattagupta --- dask_sql/physical/rex/core/call.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/dask_sql/physical/rex/core/call.py b/dask_sql/physical/rex/core/call.py index b65956254..1903c8fd9 100644 --- a/dask_sql/physical/rex/core/call.py +++ b/dask_sql/physical/rex/core/call.py @@ -44,9 +44,7 @@ def as_timelike(op): return np.timedelta64(op, "D") elif isinstance(op, str): return np.datetime64(op) - elif pd.api.types.is_datetime64_dtype(op): - return op - elif isinstance(op, np.timedelta64): + elif pd.api.types.is_datetime64_dtype(op) or isinstance(op, np.timedelta64): return op else: raise ValueError(f"Don't know how to make {type(op)} timelike")