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

Clean up Xarray dtype #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions traittypes/traittypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class XarrayType(SciType):
info_text = 'an xarray dataset or dataarray'

klass = None
dtype = None

def validate(self, obj, value):
if value is None and not self.allow_none:
Expand All @@ -234,7 +235,7 @@ def set(self, obj, value):
not old_value.equals(new_value)):
obj._notify_trait(self.name, old_value, new_value)

def __init__(self, default_value=Empty, allow_none=False, klass=None, **kwargs):
def __init__(self, default_value=Empty, allow_none=False, klass=None, dtype=None, **kwargs):
if klass is None:
klass = self.klass
if (klass is not None) and inspect.isclass(klass):
Expand All @@ -246,6 +247,8 @@ def __init__(self, default_value=Empty, allow_none=False, klass=None, **kwargs):
default_value = klass()
elif default_value is not None and default_value is not Undefined:
default_value = klass(default_value)

self.dtype = dtype
super(XarrayType, self).__init__(default_value=default_value, allow_none=allow_none, **kwargs)

def make_dynamic_default(self):
Expand Down Expand Up @@ -274,12 +277,10 @@ class DataArray(XarrayType):
"""An xarray dataarray trait type."""

info_text = 'an xarray dataarray'
dtype = None

def __init__(self, default_value=Empty, allow_none=False, dtype=None, **kwargs):
if 'klass' not in kwargs and self.klass is None:
import xarray as xr
kwargs['klass'] = xr.DataArray
super(DataArray, self).__init__(
default_value=default_value, allow_none=allow_none, dtype=dtype, **kwargs)
self.dtype = dtype