-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add .dt and .str accessors to DataArray (like pandas.Series) #358
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
Comments
Working on a project today which would greatly benefit from having the .dt accessors. Given that this issue is nearly two years old, any thoughts on what it would take to resolve in the present codebase? Still as straightforward as wrappers on the pandas time series methods? |
Yes, I think this would be quite straightforward. I think the easiest way to do it would simply be to reuse xarray's accessor interface (i.e., |
Proof of concept, borrowing liberally from pandas. I think this will be pretty straightforward to hook up into xarray. I wonder, is there any way to register such an accessor with |
Yes, looks pretty good. It would be nice to consolidate this with xarray's current logic for getting virtual datetime variables (they should probably delegate to the accessor): Line 41 in 9479038
The simplest option is to raise @xarray.register_dataarray_accessor('float_only')
class FloatOnlyAccessor(object):
def __init__(self, parent):
if parent.dtype.kind != 'f':
raise TypeError('wrong dtype')
self.parent = parent
|
Something like this should work:
observed.time.dt.to_pydatetime()
.This could simply be wrappers of the pandas methods.
The text was updated successfully, but these errors were encountered: