Skip to content

Commit 36f76c6

Browse files
Give more informative errors for unsupported dtypes
1 parent 8e845aa commit 36f76c6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Diff for: mcbackend/backends/clickhouse.py

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def create_runs_table(client: clickhouse_driver.Client):
4949

5050

5151
def column_spec_for(var: Variable, is_stat: bool = False):
52+
if var.dtype not in CLICKHOUSE_DTYPES:
53+
raise KeyError(
54+
f"Don't know how to store dtype {var.dtype} "
55+
f"of '{var.name}' (is_stat={is_stat}) in ClickHouse."
56+
)
5257
cdt = CLICKHOUSE_DTYPES[var.dtype]
5358
ndim = len(var.shape)
5459
for _ in range(ndim):

Diff for: mcbackend/test_backend_clickhouse.py

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ClickHouseBackend,
1414
ClickHouseChain,
1515
ClickHouseRun,
16+
column_spec_for,
1617
create_chain_table,
1718
)
1819
from mcbackend.core import Run, chain_id
@@ -27,6 +28,17 @@
2728
HAS_REAL_DB = False
2829

2930

31+
def test_column_spec_for():
32+
assert column_spec_for(Variable("A", "float32", [])) == "`A` Float32"
33+
assert column_spec_for(Variable("A", "float32", []), is_stat=True) == "`__stat_A` Float32"
34+
assert column_spec_for(Variable("A", "float32", [2])) == "`A` Array(Float32)"
35+
assert column_spec_for(Variable("A", "float32", [2, 3])) == "`A` Array(Array(Float32))"
36+
with pytest.raises(KeyError, match="float16 of 'A'"):
37+
column_spec_for(Variable("A", "float16", []))
38+
pass
39+
40+
41+
3042
def fully_initialized(
3143
cbackend: ClickHouseBackend, rmeta: RunMeta, *, nchains: int = 1
3244
) -> Tuple[ClickHouseRun, Sequence[ClickHouseChain]]:

0 commit comments

Comments
 (0)