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

BUG: Rolling on Dataset #859

Closed
max-sixty opened this issue May 24, 2016 · 7 comments · Fixed by #1289
Closed

BUG: Rolling on Dataset #859

max-sixty opened this issue May 24, 2016 · 7 comments · Fixed by #1289

Comments

@max-sixty
Copy link
Collaborator

This looks like it's available with dir / tab complete, but actually isn't:

In [13]: xr.DataArray(np.random.rand(10,3)).to_dataset('dim_1').rolling
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-13-438d3638a0d0> in <module>()
----> 1 xr.DataArray(np.random.rand(10,3)).to_dataset('dim_1').rolling

/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/xarray/core/common.py in __getattr__(self, name)
    135                     return source[name]
    136         raise AttributeError("%r object has no attribute %r" %
--> 137                              (type(self).__name__, name))
    138 
    139     def __setattr__(self, name, value):

AttributeError: 'Dataset' object has no attribute 'rolling'

I think this could be easy to implement as an .apply operation? (indeed, that could be a reasonable path for a whole host of operations - i.e. try and apply them to each array in the ds?)

Also, as a very narrow point, I'm not sure why .rolling_cls is public? Probably should be private?

Finally, the Rolling implementation is pretty sweet. I've been getting my hands dirty in the pandas one recently, and that we can have something as well featured as that with so few lines of code 👍

@max-sixty
Copy link
Collaborator Author

CC @jhamman

@jhamman
Copy link
Member

jhamman commented May 24, 2016

@MaximilianR - nice catch. I originally implemented the rolling method in BaseDataObject intending to scale this up to the dataset. Time ran out and my immediate application didn't need a dataset version of the method but I never moved it out of the BaseDataObject.

As you mentioned, I don't think it will be difficult to build a rolling method for the Dataset.

As for the public/private point, I'm not sure what to say. I just matched the implementation of groupby_cls.

Glad you're enjoying the rolling method!

@max-sixty
Copy link
Collaborator Author

I just matched the implementation of groupby_cls.

Right, that should be private too

@shoyer
Copy link
Member

shoyer commented May 25, 2016

I think this could be easy to implement as an .apply operation? (indeed, that could be a reasonable path for a whole host of operations - i.e. try and apply them to each array in the ds?)

Agreed, this should be pretty easy!

@fmaussion
Copy link
Member

This just happened to me too:

In [1]: import xarray as xr
In [2]: ds = xr.open_dataset('ERA-Int-Monthly-UVSLP.nc')
In [3]: ds = ds.rolling()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-16ff572cfc35> in <module>()
----> 1 ds = ds.rolling()

/home/mowglie/Documents/git/xarray/xarray/core/common.py in rolling(self, min_periods, center, **windows)
    507         """
    508 
--> 509         return self.rolling_cls(self, min_periods=min_periods,
    510                                 center=center, **windows)
    511 

/home/mowglie/Documents/git/xarray/xarray/core/common.py in __getattr__(self, name)
    224                     return source[name]
    225         raise AttributeError("%r object has no attribute %r" %
--> 226                              (type(self).__name__, name))
    227 
    228     def __setattr__(self, name, value):

AttributeError: 'Dataset' object has no attribute 'rolling_cls'

@tdennist
Copy link

Did this ever get fixed?

@max-sixty
Copy link
Collaborator Author

Did this ever get fixed?

Not fixed yet, but PRs welcome

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

Successfully merging a pull request may close this issue.

5 participants