Skip to content

Commit e6337a2

Browse files
committed
fix is_awkward_like logic; use _meta like rest of Dask
1 parent 37f05a7 commit e6337a2

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/dask_histogram/core.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def __init__(
243243
) -> None:
244244
self._dask: HighLevelGraph = dsk
245245
self._name: str = name
246-
self._histref: bh.Histogram = histref
246+
self._meta: bh.Histogram = histref
247247

248248
# NOTE: Layer only used by `Item.from_delayed`, to handle
249249
# Delayed objects created by other collections. e.g.:
@@ -303,7 +303,7 @@ def dask(self) -> HighLevelGraph:
303303
@property
304304
def histref(self) -> bh.Histogram:
305305
"""Empty reference boost-histogram object."""
306-
return self._histref
306+
return self._meta
307307

308308
@property
309309
def _storage_type(self) -> type[bh.storage.Storage]:
@@ -337,7 +337,7 @@ def __str__(self) -> str:
337337
__repr__ = __str__
338338

339339
def __reduce__(self):
340-
return (AggHistogram, (self._dask, self._name, self._histref))
340+
return (AggHistogram, (self._dask, self._name, self._meta))
341341

342342
def to_dask_array(
343343
self, flow: bool = False, dd: bool = False
@@ -457,7 +457,7 @@ def __init__(
457457
self._dask: HighLevelGraph = dsk
458458
self._name: str = name
459459
self._npartitions: int = npartitions
460-
self._histref: bh.Histogram = histref
460+
self._meta: bh.Histogram = histref
461461

462462
@property
463463
def name(self) -> str:
@@ -513,14 +513,14 @@ def __reduce__(self):
513513
self._dask,
514514
self._name,
515515
self._npartitions,
516-
self._histref,
516+
self._meta,
517517
),
518518
)
519519

520520
@property
521521
def histref(self) -> bh.Histogram:
522522
"""boost_histogram.Histogram: reference histogram."""
523-
return self._histref
523+
return self._meta
524524

525525
def collapse(self, split_every: int | None = None) -> AggHistogram:
526526
"""Translate into a reduced aggregated histogram."""
@@ -909,4 +909,19 @@ def factory(
909909

910910

911911
def is_awkward_like(x: Any) -> bool:
912-
return is_dask_collection(x) and hasattr(x, "_typetracer")
912+
"""Check if an object is Awkward collection like.
913+
914+
Parameters
915+
----------
916+
x : Any
917+
The object of interest.
918+
919+
Returns
920+
-------
921+
bool
922+
``True`` if `x` is an Awkward Dask collection.
923+
924+
"""
925+
return (
926+
hasattr(x, "__dask_graph__") and hasattr(x, "layout") and hasattr(x, "fields")
927+
)

0 commit comments

Comments
 (0)