From 6aa7fd1e9d29fd146a2d0f687f344d3734530cef Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Thu, 9 Jun 2016 11:18:30 +0100
Subject: [PATCH] Made redim interface method consistent with user API
---
holoviews/core/data/__init__.py | 13 ++++++-------
holoviews/core/data/dictionary.py | 4 ++--
holoviews/core/data/interface.py | 2 +-
holoviews/core/data/iris.py | 10 +++++-----
holoviews/core/data/ndelement.py | 4 ++--
holoviews/core/data/pandas.py | 5 +++--
holoviews/core/dimension.py | 6 +++---
7 files changed, 22 insertions(+), 22 deletions(-)
diff --git a/holoviews/core/data/__init__.py b/holoviews/core/data/__init__.py
index d22990099b..1b341a0269 100644
--- a/holoviews/core/data/__init__.py
+++ b/holoviews/core/data/__init__.py
@@ -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):
@@ -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):
diff --git a/holoviews/core/data/dictionary.py b/holoviews/core/data/dictionary.py
index c825dc737e..06574d0b20 100644
--- a/holoviews/core/data/dictionary.py
+++ b/holoviews/core/data/dictionary.py
@@ -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
diff --git a/holoviews/core/data/interface.py b/holoviews/core/data/interface.py
index 5eb9f1e9f0..c9fceb348f 100644
--- a/holoviews/core/data/interface.py
+++ b/holoviews/core/data/interface.py
@@ -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
diff --git a/holoviews/core/data/iris.py b/holoviews/core/data/iris.py
index 162a2f9379..3f779e12f3 100644
--- a/holoviews/core/data/iris.py
+++ b/holoviews/core/data/iris.py
@@ -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)
- for coord in dataset.data.dim_coords:
+ new_dataset.rename(new_dim.name)
+ for coord in new_dataset.data.dim_coords:
if name == coord.name():
- coord.rename(new_name)
+ coord.rename(new_dim.name)
return new_dataset
diff --git a/holoviews/core/data/ndelement.py b/holoviews/core/data/ndelement.py
index 5af397558e..8713fd820d 100644
--- a/holoviews/core/data/ndelement.py
+++ b/holoviews/core/data/ndelement.py
@@ -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):
diff --git a/holoviews/core/data/pandas.py b/holoviews/core/data/pandas.py
index 852023f339..f2b04de1e0 100644
--- a/holoviews/core/data/pandas.py
+++ b/holoviews/core/data/pandas.py
@@ -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
diff --git a/holoviews/core/dimension.py b/holoviews/core/dimension.py
index 16ea963103..0033505033 100644
--- a/holoviews/core/dimension.py
+++ b/holoviews/core/dimension.py
@@ -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