-
-
Notifications
You must be signed in to change notification settings - Fork 404
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
Improve import times #3055
Improve import times #3055
Changes from 4 commits
cb121ce
e78d46d
08e26ff
14510e3
feba8ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,12 @@ | |
import numpy as np | ||
import param | ||
|
||
from ..dimension import redim | ||
from ..util import unique_iterator | ||
from ..dimension import redim, Dimension, process_dimensions | ||
from ..element import Element | ||
from ..ndmapping import OrderedDict | ||
from ..spaces import HoloMap, DynamicMap | ||
from ..util import (basestring, dimension_range as d_range, get_param_values, | ||
isfinite, process_ellipses, unique_iterator, wrap_tuple) | ||
from .interface import Interface, iloc, ndloc | ||
from .array import ArrayInterface | ||
from .dictionary import DictInterface | ||
|
@@ -34,7 +38,6 @@ | |
'following error: %s' % e) | ||
|
||
try: | ||
import xarray # noqa (Availability import) | ||
from .xarray import XArrayInterface # noqa (Conditional API import) | ||
datatypes.append('xarray') | ||
except ImportError: | ||
|
@@ -49,11 +52,6 @@ | |
if 'array' not in datatypes: | ||
datatypes.append('array') | ||
|
||
from ..dimension import Dimension, process_dimensions | ||
from ..element import Element | ||
from ..ndmapping import OrderedDict | ||
from ..spaces import HoloMap, DynamicMap | ||
from .. import util | ||
|
||
|
||
def concat(datasets, datatype=None): | ||
|
@@ -210,7 +208,7 @@ class Dataset(Element): | |
|
||
def __init__(self, data, kdims=None, vdims=None, **kwargs): | ||
if isinstance(data, Element): | ||
pvals = util.get_param_values(data) | ||
pvals = get_param_values(data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove the namespace qualification? Does it affect the import times? (It shouldn't!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment above, I can have another look at this but:
|
||
kwargs.update([(l, pvals[l]) for l in ['group', 'label'] | ||
if l in pvals and l not in kwargs]) | ||
kwargs.update(process_dimensions(kdims, vdims)) | ||
|
@@ -281,15 +279,15 @@ def range(self, dim, data_range=True, dimension_range=True): | |
|
||
if dim is None or (not data_range and not dimension_range): | ||
return (None, None) | ||
elif all(util.isfinite(v) for v in dim.range) and dimension_range: | ||
elif all(isfinite(v) for v in dim.range) and dimension_range: | ||
return dim.range | ||
elif dim in self.dimensions() and data_range and len(self): | ||
lower, upper = self.interface.range(self, dim) | ||
else: | ||
lower, upper = (np.NaN, np.NaN) | ||
if not dimension_range: | ||
return lower, upper | ||
return util.dimension_range(lower, upper, dim.range, dim.soft_range) | ||
return d_range(lower, upper, dim.range, dim.soft_range) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I prefer the old version...I don't see why the name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, see the comment above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, really it is two things:
This PR would be greatly simplified if 1 can be fixed! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having nightmares with this, but I should be able to fix it. |
||
|
||
|
||
def add_dimension(self, dimension, dim_pos, dim_val, vdim=False, **kwargs): | ||
|
@@ -299,7 +297,7 @@ def add_dimension(self, dimension, dim_pos, dim_val, vdim=False, **kwargs): | |
dimensions and a key value scalar or sequence of the same length | ||
as the existing keys. | ||
""" | ||
if isinstance(dimension, (util.basestring, tuple)): | ||
if isinstance(dimension, (basestring, tuple)): | ||
dimension = Dimension(dimension) | ||
|
||
if dimension.name in self.kdims: | ||
|
@@ -398,7 +396,7 @@ def __getitem__(self, slices): | |
(4) A boolean array index matching the length of the Dataset | ||
object. | ||
""" | ||
slices = util.process_ellipses(self, slices, vdim_selection=True) | ||
slices = process_ellipses(self, slices, vdim_selection=True) | ||
if isinstance(slices, np.ndarray) and slices.dtype.kind == 'b': | ||
if not len(slices) == len(self): | ||
raise IndexError("Boolean index must match length of sliced object") | ||
|
@@ -466,11 +464,11 @@ def sample(self, samples=[], closest=True, **kwargs): | |
reindexed = selection.clone(new_type=Dataset).reindex(kdims) | ||
selection = tuple(reindexed.columns(kdims+self.vdims).values()) | ||
|
||
datatype = list(util.unique_iterator(self.datatype+['dataframe', 'dict'])) | ||
datatype = list(unique_iterator(self.datatype+['dataframe', 'dict'])) | ||
return self.clone(selection, kdims=kdims, new_type=new_type, | ||
datatype=datatype) | ||
|
||
lens = set(len(util.wrap_tuple(s)) for s in samples) | ||
lens = set(len(wrap_tuple(s)) for s in samples) | ||
if len(lens) > 1: | ||
raise IndexError('Sample coordinates must all be of the same length.') | ||
|
||
|
@@ -479,7 +477,7 @@ def sample(self, samples=[], closest=True, **kwargs): | |
samples = self.closest(samples) | ||
except NotImplementedError: | ||
pass | ||
samples = [util.wrap_tuple(s) for s in samples] | ||
samples = [wrap_tuple(s) for s in samples] | ||
return self.clone(self.interface.sample(self, samples), new_type=Table) | ||
|
||
|
||
|
@@ -574,7 +572,7 @@ def groupby(self, dimensions=[], container_type=HoloMap, group_type=None, | |
group_dims = [kd for kd in self.kdims if kd not in dimensions] | ||
kdims = [self.get_dimension(d) for d in kwargs.pop('kdims', group_dims)] | ||
drop_dim = len(group_dims) != len(kdims) | ||
group_kwargs = dict(util.get_param_values(self), kdims=kdims) | ||
group_kwargs = dict(get_param_values(self), kdims=kdims) | ||
group_kwargs.update(kwargs) | ||
def load_subset(*args): | ||
constraint = dict(zip(dim_names, args)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some weird issues when importing
from .. import util
getting the wrong utilities, hence I did this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I would prefer to figure out the issue rather than switching to the unqualified version...