MCPcopy Create free account
hub / github.com/PyTables/PyTables / _assign_values

Method _assign_values

tables/vlarray.py:701–740  ·  view source on GitHub ↗

Assign the `values` to the positions stated in `coords`.

(self, coords: Sequence[int], values: Sequence)

Source from the content-addressed store, hash-verified

699 raise IndexError(f"Invalid index or slice: {key!r}")
700
701 def _assign_values(self, coords: Sequence[int], values: Sequence) -> None:
702 """Assign the `values` to the positions stated in `coords`."""
703 for nrow, value in zip(coords, values):
704 if nrow >= self.nrows:
705 raise IndexError("First index out of range")
706 if nrow < 0:
707 # To support negative values
708 nrow += self.nrows
709 object_ = value
710 # Prepare the object to convert it into a NumPy object
711 atom = self.atom
712 if not hasattr(atom, "size"): # it is a pseudo-atom
713 object_ = atom.toarray(object_)
714 statom = atom.base
715 else:
716 statom = atom
717 value = convert_to_np_atom(object_, statom)
718 nobjects = self._getnobjects(value)
719
720 # Get the previous value
721 nrow = idx2long(nrow) # To convert any possible numpy scalar value
722 nparr = self._read_array(nrow, nrow + 1, 1)[0]
723 nobjects = len(nparr)
724 if len(value) > nobjects:
725 raise ValueError(
726 "Length of value (%s) is larger than number "
727 "of elements in row (%s)" % (len(value), nobjects)
728 )
729 try:
730 nparr[:] = value
731 except Exception as exc: # XXX
732 raise ValueError(
733 "Value parameter:\n'%r'\n"
734 "cannot be converted into an array object "
735 "compliant vlarray[%s] row: \n'%r'\n"
736 "The error was: <%s>" % (value, nrow, nparr[:], exc)
737 )
738
739 if nparr.size > 0:
740 self._modify(nrow, nparr, nobjects)
741
742 def __setitem__(
743 self,

Callers 1

__setitem__Method · 0.95

Calls 4

_getnobjectsMethod · 0.95
convert_to_np_atomFunction · 0.85
idx2longFunction · 0.85
toarrayMethod · 0.45

Tested by

no test coverage detected