Skip to content

Commit

Permalink
Give more informative errors for unsupported dtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelosthege committed Dec 2, 2022
1 parent 8e845aa commit d504c77
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mcbackend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
pass


__version__ = "0.2.4"
__version__ = "0.2.5"
5 changes: 5 additions & 0 deletions mcbackend/backends/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def create_runs_table(client: clickhouse_driver.Client):


def column_spec_for(var: Variable, is_stat: bool = False):
if var.dtype not in CLICKHOUSE_DTYPES:
raise KeyError(
f"Don't know how to store dtype {var.dtype} "
f"of '{var.name}' (is_stat={is_stat}) in ClickHouse."
)
cdt = CLICKHOUSE_DTYPES[var.dtype]
ndim = len(var.shape)
for _ in range(ndim):
Expand Down
11 changes: 11 additions & 0 deletions mcbackend/test_backend_clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ClickHouseBackend,
ClickHouseChain,
ClickHouseRun,
column_spec_for,
create_chain_table,
)
from mcbackend.core import Run, chain_id
Expand All @@ -27,6 +28,16 @@
HAS_REAL_DB = False


def test_column_spec_for():
assert column_spec_for(Variable("A", "float32", [])) == "`A` Float32"
assert column_spec_for(Variable("A", "float32", []), is_stat=True) == "`__stat_A` Float32"
assert column_spec_for(Variable("A", "float32", [2])) == "`A` Array(Float32)"
assert column_spec_for(Variable("A", "float32", [2, 3])) == "`A` Array(Array(Float32))"
with pytest.raises(KeyError, match="float16 of 'A'"):
column_spec_for(Variable("A", "float16", []))
pass


def fully_initialized(
cbackend: ClickHouseBackend, rmeta: RunMeta, *, nchains: int = 1
) -> Tuple[ClickHouseRun, Sequence[ClickHouseChain]]:
Expand Down

0 comments on commit d504c77

Please sign in to comment.