Skip to content

Commit d504c77

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

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

mcbackend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
pass
2121

2222

23-
__version__ = "0.2.4"
23+
__version__ = "0.2.5"

mcbackend/backends/clickhouse.py

Lines changed: 5 additions & 0 deletions
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):

mcbackend/test_backend_clickhouse.py

Lines changed: 11 additions & 0 deletions
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,16 @@
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+
3041
def fully_initialized(
3142
cbackend: ClickHouseBackend, rmeta: RunMeta, *, nchains: int = 1
3243
) -> Tuple[ClickHouseRun, Sequence[ClickHouseChain]]:

0 commit comments

Comments
 (0)