Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: DataTree.__init__() got an unexpected keyword argument 'data' #226

Closed
nicrie opened this issue Sep 12, 2024 · 0 comments · Fixed by #227 or #234
Closed

TypeError: DataTree.__init__() got an unexpected keyword argument 'data' #226

nicrie opened this issue Sep 12, 2024 · 0 comments · Fixed by #227 or #234
Labels
bug Something isn't working

Comments

@nicrie
Copy link
Contributor

nicrie commented Sep 12, 2024

Describe the bug

With the recent release of xarray 2024.9 fitting rotator models results in the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File /home/nrieger/Projects/teleconnections/mca.py:6
      eof.fit(X, dim="time")
      rot = xe.single.EOFRotator(n_modes=3)
----> rot.fit(eof)

File ~/Projects/xeofs/xeofs/single/eof_rotator.py:115, in EOFRotator.fit(self, model)
    self._fit_algorithm(model)
    if self._params["compute"]:
-->   self.compute()
     return self

File ~/Projects/xeofs/xeofs/base_model.py:64, in BaseModel.compute(self, **kwargs)
     """Compute and load delayed model results.
     
     Parameters
   (...)
     Additional keyword arguments to pass to `dask.compute()`.
     """
     # find and compute all dask arrays simultaneously to allow dask to optimize the
     # shared graph and avoid duplicate i/o and computations
---> dt = self.serialize()
     data_objs = {
          k: v
          for k, v in dt.to_dict().items()
          if data_is_dask(v) and v.attrs.get("allow_compute", True)
     }
     (data_objs,) = dask.base.compute(data_objs, **kwargs)

File ~/Projects/xeofs/xeofs/base_model.py:93, in BaseModel.serialize(self)
     # Create a root node for this object with its params as attrs
     ds_root = xr.Dataset(attrs=dict(params=self.get_params()))
---> dt = DataTree(data=ds_root, name=type(self).__name__)
     # Retrieve the tree representation of each attached object, or set basic attrs
     for key, attr in self.get_serialization_attrs().items():

TypeError: DataTree.__init__() got an unexpected keyword argument 'data'

Reproducible Minimal Working Example

import xarray as xr
import xeofs as xe

X = xr.tutorial.open_dataset("air_temperature").air

eof = xe.single.EOF(n_modes=3)
eof.fit(X, dim="time")
rot = xe.single.EOFRotator(n_modes=3)
rot.fit(eof)   <- fails!

Expected behavior
Rotation runs without error.

Desktop (please complete the following information):

  • OS: Ubuntu 22.04
  • xeofs version 3.0.1

Additional context
Just checking the what's new page of xarray, it seems that there were two merged PRs regarding datatree that may be responsible for the break: PR9276 and PR9292. Any ideas here @slevang ?

@nicrie nicrie added the bug Something isn't working label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant