Say I have multiple xarray accessors registered:
import xarray as xr
@xr.register_dataarray_accessor("a")
class A:
def __init__(self, xarray_obj):
self._obj = xarray_obj
def print(self):
return "A"
@xr.register_dataarray_accessor("b")
class B:
def __init__(self, xarray_obj):
self._obj = xarray_obj
def print(self):
return "b"
@xr.register_dataarray_accessor("c")
class C:
def __init__(self, xarray_obj):
self._obj = xarray_obj
def print(self):
return "c"
xr.DataArray().a.print()
# a
xr.DataArray().b.print()
# b
xr.DataArray().c.print()
# c
is there a good way to "move" them into a single accessor that acts as a sort of parent accessor?
Assuming this parent would be called z, my desired result would look like this:
xr.DataArray().z.a.print()
# a
xr.DataArray().z.b.print()
# b
xr.DataArray().z.c.print()
# c
Edit:
This is just a toy example, of course all the nested objects need to have access to the self._obj that Z gets.