diff --git a/src/dask_awkward/lib/core.py b/src/dask_awkward/lib/core.py index 1711504f..017b705d 100644 --- a/src/dask_awkward/lib/core.py +++ b/src/dask_awkward/lib/core.py @@ -196,15 +196,11 @@ def __str__(self) -> str: return f"dask.awkward<{key_split(self.name)}, type=Scalar, dtype={dt}>" def __getitem__(self, where: Any) -> Any: - token = tokenize(self, operator.getitem, where) - label = "getitem" - name = f"{label}-{token}" - task = AwkwardMaterializedLayer( - {(name, 0): (operator.getitem, self.key, where)}, - previous_layer_names=[self.name], + msg = ( + "__getitem__ access on Scalars should be done after converting " + "the Scalar collection to delayed with the to_delayed method." ) - hlg = HighLevelGraph.from_collections(name, task, dependencies=[self]) - return new_scalar_object(hlg, name, meta=None) + raise NotImplementedError(msg) @property def known_value(self) -> Any | None: diff --git a/tests/test_core.py b/tests/test_core.py index 4baec896..3cd1769e 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -219,7 +219,9 @@ def test_scalar_collection(daa: Array) -> None: def test_scalar_getitem_getattr() -> None: d = {"a": 5} s = new_known_scalar(d) - assert s["a"].compute() == d["a"] + with pytest.raises(NotImplementedError, match="should be done after converting"): + s["a"].compute() == d["a"] + assert s.to_delayed()["a"].compute() == d["a"] # type: ignore Thing = namedtuple("Thing", "a b c") t = Thing(c=3, b=2, a=1) s = new_known_scalar(t)