Skip to content

Commit

Permalink
Add tests for exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuhuishishishi committed Dec 7, 2020
1 parent 467b28a commit a608483
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dask_sql/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def sql_to_python_value(sql_type: str, literal_value: Any) -> Any:
# if sql_type is INTERVAL YEAR, Calcite will covert to months
delta = pd.tseries.offsets.DateOffset(months=float(str(literal_value)))
return delta
except IndexError:
except IndexError: # pragma: no cover
# no finer granular interval type specified
pass
except TypeError:
except TypeError: # pragma: no cover
# interval type is not recognized, fall back to default case
pass

Expand Down
21 changes: 16 additions & 5 deletions tests/integration/test_rex.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime

import pytest
import numpy as np
import pandas as pd
import dask.dataframe as dd
Expand Down Expand Up @@ -452,11 +453,11 @@ def test_date_functions(c):
CEIL(d TO SECOND) as ceil_to_seconds,
CEIL(d TO MILLISECOND) as ceil_to_millisec,
floor(d TO DAY) as floor_to_day,
floor(d TO HOUR) as floor_to_hour,
floor(d TO MINUTE) as floor_to_minute,
floor(d TO SECOND) as floor_to_seconds,
floor(d TO MILLISECOND) as floor_to_millisec
FLOOR(d TO DAY) as floor_to_day,
FLOOR(d TO HOUR) as floor_to_hour,
FLOOR(d TO MINUTE) as floor_to_minute,
FLOOR(d TO SECOND) as floor_to_seconds,
FLOOR(d TO MILLISECOND) as floor_to_millisec
FROM df
"""
Expand Down Expand Up @@ -503,3 +504,13 @@ def test_date_functions(c):
)

assert_frame_equal(df, expected_df, check_dtype=False)

# test exception handling
with pytest.raises(NotImplementedError):
df = c.sql(
"""
SELECT
FLOOR(d TO YEAR) as floor_to_year
FROM df
"""
).compute()

0 comments on commit a608483

Please sign in to comment.