Skip to content

Commit

Permalink
GroupNode linkages
Browse files Browse the repository at this point in the history
  • Loading branch information
jpn-- committed Feb 13, 2017
1 parent 8a4ea77 commit 44d14bb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 9 additions & 2 deletions py/dt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2658,7 +2658,7 @@ def pluck_into_idco(self, other_omx, rowindexes, colindexes, names=None, overwri



def new_idca(self, name, expression, title=None, dtype=None):
def new_idca(self, name, expression, title=None, dtype=None, original_source="externally defined array"):
"""Create a new :ref:`idca` variable.
Creating a new variable in the data might be convenient in some instances.
Expand All @@ -2680,6 +2680,10 @@ def new_idca(self, name, expression, title=None, dtype=None):
Give a description of the data in this array.
dtype : dtype, optional
What numpy dtype should the new array should be, defaults to float64.
original_source : str, optional
If `expression` is an array, provide this string as the "original source"
of the data. If omitted, the original source is set as the generic
"externally defined array".
Raises
-----
Expand All @@ -2696,7 +2700,10 @@ def new_idca(self, name, expression, title=None, dtype=None):
else:
data = expression
self.h5f.create_carray(self.idca._v_node, name, obj=data)
self.idca[name]._v_attrs.ORIGINAL_SOURCE = "= {}".format(expression)
if isinstance(expression, str):
self.idca[name]._v_attrs.ORIGINAL_SOURCE = "= {}".format(expression)
else:
self.idca[name]._v_attrs.ORIGINAL_SOURCE = original_source
if title is not None:
self.idca[name]._v_attrs.TITLE = title

Expand Down
12 changes: 12 additions & 0 deletions py/dt/groupnode.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,18 @@ def add_external_data(self, link):
return self._v_file.create_external_link(self._v_node, '_extern_{}'.format(extern_n), link)


def add_external_node(self, name, link):
"""
Add a linkage to a single external node.
"""
if isinstance(link, GroupNode):
fname = link._v_node._v_file.filename
if fname == self._v_node._v_file.filename:
raise TypeError('cannot link to external data in same file, try a local link')
link = fname +":"+ link._v_node._v_pathname
return self._v_file.create_external_link(self._v_node, name, link)


def add_external_omx(self, omx_filename, rowindexnode, prefix="", n_alts=-1, n_lookup=-1, absolute_path=False, local_rowindexnode=None, suppress_identifier_warning=False):
'''
Add an external linkage from this group to the values in an OMX file.
Expand Down
13 changes: 9 additions & 4 deletions py/dt/stack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,17 @@ def __getitem__(self, key):
raise KeyError("key {} not found".format(key) )

def __setitem__(self, key, value):
if self.stacktype not in self.parent.idca:
self._make_zeros()
if 'stack' not in self.parent.idca[self.stacktype]._v_attrs and not self.parent.in_vault('stack.'+self.stacktype):
self._make_zeros()

if len(self._stackdef_vault) < self.parent._alternative_codes().size:
self._stackdef_vault += [0] * (self.parent._alternative_codes().size - len(self._stackdef_vault))
if len(self._stackdef_vault) > self.parent._alternative_codes().size:
self._stackdef_vault = self._stackdef_vault[:self.parent._alternative_codes().size]
slotarray = numpy.where(self.parent._alternative_codes()==key)[0]
if len(slotarray) == 1:
if self.stacktype not in self.parent.idca:
self._make_zeros()
if 'stack' not in self.parent.idca[self.stacktype]._v_attrs and not self.parent.in_vault('stack.'+self.stacktype):
self._make_zeros()
##tempobj = self.parent.idca[self.stacktype]._v_attrs.stack
tempobj = self._stackdef_vault
tempobj[slotarray[0]] = value
Expand Down

0 comments on commit 44d14bb

Please sign in to comment.