Skip to content

Commit 6598259

Browse files
committed
added test for datetime
1 parent bb51125 commit 6598259

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/integration/test_compatibility.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
from dask_sql import Context
2020

2121

22+
def cast_datetime_to_string(df):
23+
cols = df.select_dtypes(include=["datetime64[ns]"]).columns
24+
# Casting to object first as
25+
# directly converting to string looses second precision
26+
df[cols] = df[cols].astype("object").astype("string")
27+
return df
28+
29+
2230
def eq_sqlite(sql, **dfs):
2331
c = Context()
2432
engine = sqlite3.connect(":memory:")
@@ -30,6 +38,10 @@ def eq_sqlite(sql, **dfs):
3038
dask_result = c.sql(sql).compute().reset_index(drop=True)
3139
sqlite_result = pd.read_sql(sql, engine).reset_index(drop=True)
3240

41+
# casting to object to ensure equality with sql-lite
42+
# which returns object dtype for datetime inputs
43+
dask_result = cast_datetime_to_string(dask_result)
44+
3345
# Make sure SQL and Dask use the same "NULL" value
3446
dask_result = dask_result.fillna(np.NaN)
3547
sqlite_result = sqlite_result.fillna(np.NaN)
@@ -349,6 +361,7 @@ def test_agg_min_max_no_group_by():
349361
d=(str, 40),
350362
e=(float, 40),
351363
f=(pd.StringDtype, 40),
364+
g=(datetime, 40),
352365
)
353366
eq_sqlite(
354367
"""
@@ -365,6 +378,8 @@ def test_agg_min_max_no_group_by():
365378
MAX(e) AS max_e,
366379
MIN(f) as min_f,
367380
MAX(f) as max_f,
381+
MIN(g) as min_g,
382+
MAX(g) as max_g,
368383
MIN(a+e) AS mix_1,
369384
MIN(a)+MIN(e) AS mix_2
370385
FROM a
@@ -382,6 +397,7 @@ def test_agg_min_max():
382397
d=(str, 40),
383398
e=(float, 40),
384399
f=(pd.StringDtype, 40),
400+
g=(datetime, 40),
385401
)
386402
eq_sqlite(
387403
"""
@@ -395,6 +411,8 @@ def test_agg_min_max():
395411
MAX(e) AS max_e,
396412
MIN(f) AS min_f,
397413
MAX(f) AS max_f,
414+
MIN(g) AS min_g,
415+
MAX(g) AS max_g,
398416
MIN(a+e) AS mix_1,
399417
MIN(a)+MIN(e) AS mix_2
400418
FROM a GROUP BY a, b

0 commit comments

Comments
 (0)