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

Implemented redim method on Dimensioned objects #715

Merged
merged 3 commits into from Jun 9, 2016
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+23 −23
Diff settings

Always

Just for now

Prev

Made redim interface method consistent with user API

  • Loading branch information...
Philipp Rudiger Philipp Rudiger
Philipp Rudiger authored and Philipp Rudiger committed Jun 9, 2016
commit 7d56136aef4bbd9dda007dc6551bdd6245318c6b
Copy path View file
@@ -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):
@@ -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
@@ -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
Copy path View file
@@ -201,17 +201,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():
if name == dataset.data.name():
new_dataset.rename(new_name)
for coord in dataset.data.dim_coords:
for name, new_dim in dimensions.items():
if name == new_dataset.name():
new_dataset.rename(new_dim.name)
for coord in new_dataset.dim_coords:
if name == coord.name():
coord.rename(new_name)
coord.rename(new_dim.name)
return new_dataset


@@ -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):
Copy path View file
@@ -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
Copy path View file
@@ -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
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.