Beispiel #1
0
 def __init__(self, ufunc):
     if not isinstance(ufunc, (np.ufunc, da_frompyfunc)):
         raise TypeError("must be an instance of `ufunc` or "
                         "`da_frompyfunc`, got `%s" % type(ufunc).__name__)
     self._ufunc = ufunc
     self.__name__ = ufunc.__name__
     if isinstance(ufunc, np.ufunc):
         derived_from(np)(self)
Beispiel #2
0
    def _bind_elemwise_comparison_method(cls, name, comparison, original,
                                         *args, **kwargs):
        """bind comparison method like GeoSeries.contains to this class"""
        def meth(self, other, *args, **kwargs):
            return elemwise(comparison, self, other, *args, **kwargs)

        meth.__name__ = name
        setattr(cls, name, derived_from(original)(meth))
Beispiel #3
0
    def _bind_elemwise_operator_method(cls, name, op, original, *args, **kwargs):
        """ bind operator method like GeoSeries.distance to this class """
        # name must be explicitly passed for div method whose name is truediv
        def meth(self, other, *args, **kwargs):
            meta = _emulate(op, self, other)
            return map_partitions(
                op, self, other, meta=meta, enforce_metadata=False, *args, **kwargs
            )

        meth.__name__ = name
        setattr(cls, name, derived_from(original)(meth))
Beispiel #4
0
def _bind_method(cls, pd_cls, attr, min_version=None):
    def func(self, *args, **kwargs):
        return self._function_map(attr, *args, **kwargs)

    func.__name__ = attr
    func.__qualname__ = f"{cls.__name__}.{attr}"
    try:
        func.__wrapped__ = getattr(pd_cls, attr)
    except Exception:
        pass
    setattr(cls, attr, derived_from(pd_cls, version=min_version)(func))
Beispiel #5
0
def _bind_property(cls, pd_cls, attr, min_version=None):
    def func(self):
        return self._property_map(attr)

    func.__name__ = attr
    func.__qualname__ = f"{cls.__name__}.{attr}"
    try:
        func.__wrapped__ = getattr(pd_cls, attr)
    except Exception:
        pass
    setattr(cls, attr,
            property(derived_from(pd_cls, version=min_version)(func)))
Beispiel #6
0
def wrap_elemwise(numpy_ufunc, source=np):
    """Wrap up numpy function into dask.array"""
    def wrapped(*args, **kwargs):
        dsk = [arg for arg in args if hasattr(arg, "_elemwise")]
        if len(dsk) > 0:
            return dsk[0]._elemwise(numpy_ufunc, *args, **kwargs)
        else:
            return numpy_ufunc(*args, **kwargs)

    # functools.wraps cannot wrap ufunc in Python 2.x
    wrapped.__name__ = numpy_ufunc.__name__
    return derived_from(source)(wrapped)