MCPcopy Create free account
hub / github.com/dask/dask / DelayedAttr

Class DelayedAttr

dask/delayed.py:864–893  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

862
863
864class DelayedAttr(Delayed):
865 __slots__ = ("_obj", "_attr")
866
867 def __init__(self, obj, attr):
868 key = f"getattr-{tokenize(obj, attr, pure=True)}"
869 super().__init__(key, None)
870 self._obj = obj
871 self._attr = attr
872
873 def __getattr__(self, attr):
874 # Calling np.dtype(dask.delayed(...)) used to result in a segfault, as
875 # numpy recursively tries to get `dtype` from the object. This is
876 # likely a bug in numpy. For now, we can do a dumb for if
877 # `x.dtype().dtype()` is called (which shouldn't ever show up in real
878 # code). See https://github.com/dask/dask/pull/4374#issuecomment-454381465
879 if attr == "dtype" and self._attr == "dtype":
880 raise AttributeError("Attribute dtype not found")
881 return super().__getattr__(attr)
882
883 @property
884 def dask(self):
885 layer = {self._key: (getattr, self._obj._key, self._attr)}
886 return HighLevelGraph.from_collections(
887 self._key, layer, dependencies=[self._obj]
888 )
889
890 def __call__(self, *args, **kwargs):
891 return call_function(
892 methodcaller(self._attr), self._attr, (self._obj,) + args, kwargs
893 )
894
895
896for op in [

Callers 1

__getattr__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected