| 2789 | return elemwise |
| 2790 | |
| 2791 | def __array_ufunc__(self, numpy_ufunc, method, *inputs, **kwargs): |
| 2792 | out = kwargs.get("out", ()) |
| 2793 | for x in inputs + out: |
| 2794 | # ufuncs work with 0-dimensional NumPy ndarrays |
| 2795 | # so we don't want to raise NotImplemented |
| 2796 | if isinstance(x, np.ndarray) and x.shape == (): |
| 2797 | continue |
| 2798 | elif not isinstance( |
| 2799 | x, (Number, Scalar, FrameBase, Array, pd.DataFrame, pd.Series, pd.Index) |
| 2800 | ): |
| 2801 | return NotImplemented |
| 2802 | |
| 2803 | if method == "__call__": |
| 2804 | if numpy_ufunc.signature is not None: |
| 2805 | return NotImplemented |
| 2806 | if numpy_ufunc.nout > 1: |
| 2807 | # ufuncs with multiple output values |
| 2808 | # are not yet supported for frames |
| 2809 | return NotImplemented |
| 2810 | else: |
| 2811 | return elemwise(numpy_ufunc, *inputs, **kwargs) |
| 2812 | else: |
| 2813 | # ufunc methods are not yet supported for frames |
| 2814 | return NotImplemented |
| 2815 | |
| 2816 | def __array_wrap__(self, array, context=None): |
| 2817 | if isinstance(context, tuple) and len(context) > 0: |