Skip to content

Commit

Permalink
Merge pull request #539 from ioam/dimension_index_opt
Browse files Browse the repository at this point in the history
Avoided deep lookup on get_dimension_index
  • Loading branch information
jlstevens committed Mar 11, 2016
2 parents 454cc95 + 5c02d35 commit 15fdb71
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions holoviews/core/dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,15 @@ def get_dimension_index(self, dim):
"""
if isinstance(dim, Dimension): dim = dim.name
if isinstance(dim, int):
if dim < len(self.dimensions()):
if (dim < (self.ndims + len(self.vdims)) or
dim < len(self.dimensions())):
return dim
else:
return IndexError('Dimension index out of bounds')
try:
sanitized = {dimension_sanitizer(kd): kd
for kd in self.dimensions('key', True)}
return [d.name for d in self.dimensions()].index(sanitized.get(dim, dim))
if dim in self.kdims+self.vdims:
return (self.kdims+self.vdims).index(dim)
return self.dimensions().index(dim)
except ValueError:
raise Exception("Dimension %s not found in %s." %
(dim, self.__class__.__name__))
Expand Down

0 comments on commit 15fdb71

Please sign in to comment.