Implemented Dataset.get_indices() and extended Dataset.get_identifiers() to convert between indices and identifiers and subsets thereof.
Also added tests.
This commit is contained in:
@@ -172,13 +172,28 @@ class Dataset:
|
||||
"""Returns dim names"""
|
||||
return [dim for dim in self._dims]
|
||||
|
||||
def get_identifiers(self,dim):
|
||||
"""Returns identifiers aling dim, sorted by position (index)"""
|
||||
def get_identifiers(self, dim, indices=None):
|
||||
"""Returns identifiers along dim, sorted by position (index).
|
||||
|
||||
You can optionally provide a list of indices to get only the
|
||||
identifiers of a given position.
|
||||
"""
|
||||
items = self._map[dim].items()
|
||||
backitems=[ [v[1],v[0]] for v in items]
|
||||
backitems.sort()
|
||||
sorted_ids=[ backitems[i][1] for i in range(0,len(backitems))]
|
||||
return tuple(sorted_ids)
|
||||
|
||||
if indices != None:
|
||||
return [sorted_ids[index] for index in indices]
|
||||
else:
|
||||
return sorted_ids
|
||||
|
||||
def get_indices(self, dim, idents):
|
||||
"""Get indices for identifiers along dimension."""
|
||||
reverse = {}
|
||||
for key, value in self._map[dim].items():
|
||||
reverse[value] = key
|
||||
return [self._map[dim][key] for key in idents]
|
||||
|
||||
|
||||
class CategoryDataset(Dataset):
|
||||
|
Reference in New Issue
Block a user