Skip to content

Commit

Permalink
Made redim interface method consistent with user API
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jun 9, 2016
1 parent b9aad12 commit 4595067
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
13 changes: 6 additions & 7 deletions holoviews/core/data/__init__.py
Expand Up @@ -394,9 +394,8 @@ def redim(self, specs=None, **dimensions):
"""
Replace dimensions on the dataset and allows renaming
dimensions in the dataset. Dimension mapping should map
between the old dimension name and either a dictionary of the
new attributes or a completely new dimension to replace it
with.
between the old dimension name and a dictionary of the new
attributes, a completely new dimension or a new string name.
"""
if specs is not None:
if not isinstance(specs, list):
Expand All @@ -407,11 +406,11 @@ def redim(self, specs=None, **dimensions):
kdims = replace_dimensions(self.kdims, dimensions)
vdims = replace_dimensions(self.vdims, dimensions)
zipped_dims = zip(self.kdims+self.vdims, kdims+vdims)
renames = {pk.name: nk.name for pk, nk in zipped_dims if pk != nk}
renamed = self.data
renames = {pk.name: nk for pk, nk in zipped_dims if pk != nk}
data = self.data
if renames:
renamed = self.interface.rename(self, renames)
return self.clone(renamed, kdims=kdims, vdims=vdims)
data = self.interface.redim(self, renames)
return self.clone(data, kdims=kdims, vdims=vdims)


def dimension_values(self, dim, expanded=True, flat=True):
Expand Down
4 changes: 2 additions & 2 deletions holoviews/core/data/dictionary.py
Expand Up @@ -123,8 +123,8 @@ def add_dimension(cls, dataset, dimension, dim_pos, values, vdim):
return OrderedDict(data)

@classmethod
def rename(cls, dataset, renames):
return OrderedDict([(renames.get(k, k), v)
def redim(cls, dataset, dimensions):
return OrderedDict([(dimensions.get(k, dataset.get_dimension(k)).name, v)
for k,v in dataset.data.items()])

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion holoviews/core/data/interface.py
Expand Up @@ -206,5 +206,5 @@ def length(cls, dataset):
return len(dataset.data)

@classmethod
def rename(cls, dataset, renames):
def redim(cls, dataset, dimensions):
return dataset.data
8 changes: 4 additions & 4 deletions holoviews/core/data/iris.py
Expand Up @@ -199,17 +199,17 @@ def range(cls, dataset, dimension):


@classmethod
def rename(cls, dataset, renames):
def redim(cls, dataset, dimensions):
"""
Rename coords on the Cube.
"""
new_dataset = dataset.data.copy()
for name, new_name in renames.items():
for name, new_dim in dimensions.items():
if name == dataset.data.name():
new_dataset.rename(new_name)
new_dataset.rename(new_dim.name)
for coord in dataset.data.dim_coords:
if name == coord.name():
coord.rename(new_name)
coord.rename(new_dim.name)
return new_dataset


Expand Down
4 changes: 2 additions & 2 deletions holoviews/core/data/ndelement.py
Expand Up @@ -76,8 +76,8 @@ def dimension_type(cls, columns, dim):
return Dimensioned.get_dimension_type(columns, dim)

@classmethod
def rename(cls, dataset, renames):
return dataset.data.redim(**renames)
def redim(cls, dataset, dimensions):
return dataset.data.redim(**dimensions)

@classmethod
def shape(cls, columns):
Expand Down
5 changes: 3 additions & 2 deletions holoviews/core/data/pandas.py
Expand Up @@ -152,8 +152,9 @@ def reindex(cls, columns, kdims=None, vdims=None):


@classmethod
def rename(cls, dataset, renames):
return dataset.data.rename(columns=renames)
def redim(cls, dataset, dimensions):
column_renames = {k: v.name for k, v in dimensions.items()}
return dataset.data.rename(columns=column_renames)


@classmethod
Expand Down
6 changes: 3 additions & 3 deletions holoviews/core/dimension.py
Expand Up @@ -799,9 +799,9 @@ def redim(self, specs=None, **dimensions):
"""
Replaces existing dimensions in an object with new dimensions
or changing specific attributes of a dimensions. Dimension
mapping should map between the old dimension name and either a
dictionary of the new attributes or a completely new dimension
to replace it with.
mapping should map between the old dimension name and a
dictionary of the new attributes, a completely new dimension
or a new string name.
"""
if specs is None:
applies = True
Expand Down

0 comments on commit 4595067

Please sign in to comment.