Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

numpy ufuncs currently fail #25

Closed
TomNicholas opened this issue Aug 25, 2021 · 1 comment
Closed

numpy ufuncs currently fail #25

TomNicholas opened this issue Aug 25, 2021 · 1 comment

Comments

@TomNicholas
Copy link
Member

Currently calling a numpy ufunc on a DataTree (e.g. np.sin(dt)) fails with a recursion error (below).

That's probably because I just naively included Dataset.__array_ufunc__ in the list of method to decorate with @map_over_subtree, and it's needs a smarter definition.

________________________________________TestUFuncs.test_root___________________________________________

self = <test_dataset_api.TestUFuncs object at 0x7f486a542100>

    def test_root(self):
        da = xr.DataArray(name="a", data=[1, 2, 3])
        dt = DataNode("root", data=da)
        expected_ds = np.sin(da.to_dataset())
>       result_ds = np.sin(dt).ds

datatree/tests/test_dataset_api.py:179: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
datatree/datatree.py:92: in _map_over_subtree
    out_tree.ds = func(out_tree.ds, *args, **kwargs)
../xarray/xarray/core/arithmetic.py:79: in __array_ufunc__
    return apply_ufunc(
../xarray/xarray/core/computation.py:1184: in apply_ufunc
    return apply_array_ufunc(func, *args, dask=dask)
../xarray/xarray/core/computation.py:811: in apply_array_ufunc
    return func(*args)
datatree/datatree.py:92: in _map_over_subtree
    out_tree.ds = func(out_tree.ds, *args, **kwargs)
../xarray/xarray/core/arithmetic.py:79: in __array_ufunc__
    return apply_ufunc(
../xarray/xarray/core/computation.py:1184: in apply_ufunc
    return apply_array_ufunc(func, *args, dask=dask)
../xarray/xarray/core/computation.py:811: in apply_array_ufunc
    return func(*args)
datatree/datatree.py:92: in _map_over_subtree
    out_tree.ds = func(out_tree.ds, *args, **kwargs)
datatree/datatree.py:92: in _map_over_subtree
    out_tree.ds = func(out_tree.ds, *args, **kwargs)
../xarray/xarray/core/arithmetic.py:79: in __array_ufunc__
    return apply_ufunc(
../xarray/xarray/core/computation.py:1184: in apply_ufunc
    return apply_array_ufunc(func, *args, dask=dask)
../xarray/xarray/core/computation.py:793: in apply_array_ufunc
    if any(is_duck_dask_array(arg) for arg in args):
../xarray/xarray/core/computation.py:793: in <genexpr>
    if any(is_duck_dask_array(arg) for arg in args):
../xarray/xarray/core/pycompat.py:47: in is_duck_dask_array
    if DuckArrayModule("dask").available:
../xarray/xarray/core/pycompat.py:21: in __init__
    duck_array_module = import_module(mod)
/home/tom/miniconda3/envs/py38-mamba/lib/python3.8/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1011: in _gcd_import
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

name = 'dask', package = None, level = 0

>   ???
E   RecursionError: maximum recursion depth exceeded while calling a Python object

<frozen importlib._bootstrap>:939: RecursionError
!!! Recursion error detected, but an error occurred locating the origin of recursion.
  The following exception happened when comparing locals in the stack frame:
    ValueError: dimensions ('dim_0',) must have the same length as the number of data dimensions, ndim=0
  Displaying first and last 10 stack frames out of 767.
@TomNicholas
Copy link
Member Author

Closed as a side-effect of #32, and tests for this functionality enabled in #24

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant