Exemple #1
0
 def __setitem__(self, key, value):
     if len(self):
         if value.duration != self.duration:
             raise AssertionError("duration does not match")
         if value.fs != self.fs:
             raise AssertionError("fs does not match")
     UserDict.__setitem__(self, key, value)
 def __setitem__(self, key, item):
     if key == None:
         raise Exception('I don\'t know how to handle None as a key.')
     UserDict.__setitem__(self, key, item)
     if self._preferred_order and key in self._preferred_order:
         self._keys[self._preferred_order.index(key)] = key
     elif key not in self._keys: self._keys.append(key)
Exemple #3
0
 def __setitem__(self, key, value):
     self.modified = True
     log.debug("Setting key '%s' to value '%s'" % (key, value))
     if key.startswith("_"):
         self.internal_data[key] = value
     else:
         UserDict.__setitem__(self, key, value)
Exemple #4
0
    def __setitem__(self, key, value):

        if key not in self.__dict__:
            self.__keys__.append(key)
            self.__sorted__ = False

        UserDict.__setitem__(self, key, value)
Exemple #5
0
 def insert(self, Key, Newkey, Newvalue, Order):
     Index = self._key_list.index(Key)
     if Order == 'BEFORE':
         self._key_list.insert(Index, Newkey)
         IterableUserDict.__setitem__(self, Newkey, Newvalue)
     elif Order == 'AFTER':
         self._key_list.insert(Index + 1, Newkey)
         IterableUserDict.__setitem__(self, Newkey, Newvalue)
Exemple #6
0
 def __setitem__(self, key, value):
     """
     Add an item to attributes (by name or id)
     """
     try:
         code, name = self.__getkeys(key)
         values = self.get(code, [])
         values.append(value)
         UserDict.__setitem__(self, code, values)
     except KeyError:
         LOGGER.warning('Invalid radius attribute: %s' % key)
Exemple #7
0
    def __setitem__(self, key, value):
        self.update_size()

        # If this is the first column added, we must create an index column.
        add_index = False
        if self._empty:
            add_index = True

        # Set a single row in the dataframe using a dict of values
        if type(key) == int:
            for k in self.data.keys():
                if isinstance(self.data[k], ak.Strings):
                    raise ValueError(
                        "This DataFrame has a column of type ak.Strings;"
                        " so this DataFrame is immutable. This feature could change"
                        " if arkouda supports mutable Strings in the future.")
            if self._empty:
                raise ValueError(
                    "Initial data must be dict of arkouda arrays.")
            elif not isinstance(value, (dict, UserDict)):
                raise ValueError("Expected dict or Row type.")
            elif key >= self._size:
                raise KeyError("The row index is out of range.")
            else:
                for k, v in value.items():
                    if k == 'index':
                        continue
                    self[k][key] = v

        # Set a single column in the dataframe using a an arkouda array
        elif type(key) == str:
            if not isinstance(value, self.COLUMN_CLASSES):
                raise ValueError(
                    f"Column must be one of {self.COLUMN_CLASSES}.")
            elif self._size is not None and self._size != value.size:
                raise ValueError(
                    "Expected size {} but received size {}.".format(
                        self.size, value.size))
            else:
                self._empty = False
                UserDict.__setitem__(self, key, value)
                # Update the index values
                if key not in self._columns:
                    self._columns.append(key)

        # Do nothing and return if there's no valid data
        else:
            raise ValueError("No valid data received.")

        # Update the dataframe indices and metadata.
        if add_index:
            self.update_size()
            self.data['index'] = ak.arange(0, self._size, 1)
Exemple #8
0
 def __setitem__(self, option, value):
     """
     Setting an option. Do nothing if the option's value is None, so
     an option with a default value not None, cannot be assigned with
     None.
     """
     if value is None:
         return
     if option in self:
         del self[option]
     else:
         raise KeyError("Key {0} not in options".format(option))
     UserDict.__setitem__(self, option, value)
Exemple #9
0
 def __setitem__(self, option, value):
     """
     Setting an option. Do nothing if the option's value is None, so
     an option with a default value not None, cannot be assigned with
     None.
     """
     if value is None:
         return
     if option in self:
         del self[option]
     else:
         raise KeyError("Key {0} not in options".format(option))
     UserDict.__setitem__(self, option, value)
Exemple #10
0
    def __setitem__(self, key, value):
        """
        Add an item to attributes (by name or id)
        """
        try:
            code, name = self.__getkeys(key)

        except KeyError:
            raise ValueError('Unknown radius attribute: %s' % key)

        if name is None:
            LOGGER.warning('Unknown radius attribute code %s' % code)

        values = self.get(code, [])
        values.append(value)
        UserDict.__setitem__(self, code, values)
Exemple #11
0
    def __setitem__(self, key, value):
        """
        Add an item to attributes (by name or id)
        """
        try:
            code, name = self.__getkeys(key)

        except KeyError:
            raise ValueError('Unknown radius attribute: %s' % key)

        if name is None:
            LOGGER.warning('Unknown radius attribute code %s' % code)

        values = self.get(code, [])
        values.append(value)
        UserDict.__setitem__(self, code, values)
 def __setitem__(self, key, item):
     """
     Parameters
     ----------
     key: (Interface, Interface)
     item : object
     """
     key = self._get_key(*key)
     # old-style class, no super
     return UserDict.__setitem__(self, key, item)
Exemple #13
0
 def __setitem__(self, key, value: Distance) -> None:
     current: Optional[Distance] = self.get(key, None)
     if current is not None and value.aggregated > current.aggregated:
         return None
     UserDict.__setitem__(self, key, value)
Exemple #14
0
 def __setitem__(self, key: str, value: Union[SpanGroup,
                                              Iterable["Span"]]) -> None:
     if not isinstance(value, SpanGroup):
         value = self._make_span_group(key, value)
     assert value.doc is self.doc_ref()
     UserDict.__setitem__(self, key, value)
Exemple #15
0
    def __init__(self, initialdata=None):
        super().__init__()

        if isinstance(initialdata, DataFrame):
            # Copy constructor
            self._size = initialdata._size
            self._bytes = initialdata._bytes
            self._empty = initialdata._empty
            self._columns = initialdata._columns
            self.data = initialdata.data
            self.update_size()
            return

        # Some metadata about this dataframe.
        self._size = 0
        self._bytes = 0
        self._empty = True

        # Initial attempts to keep an order on the columns
        self._columns = ['index']
        self.data['index'] = None

        # Add data to the DataFrame if there is any
        if initialdata is not None:
            # Used to prevent uneven array length in initialization.
            sizes = set()

            # Initial data is a dictionary of arkouda arrays
            if type(initialdata) == dict:
                for key, val in initialdata.items():
                    if not isinstance(val, self.COLUMN_CLASSES):
                        raise ValueError(
                            f"Values must be one of {self.COLUMN_CLASSES}.")
                    sizes.add(val.size)
                    if len(sizes) > 1:
                        raise ValueError("Input arrays must have equal size.")
                    self._empty = False
                    UserDict.__setitem__(self, key, val)
                    # Update the column index
                    if key != 'index':
                        self._columns.append(key)

            # Initial data is a list of arkouda arrays
            elif type(initialdata) == list:
                # Create string IDs for the columns
                keys = [str(x) for x in range(len(initialdata))]
                for key, col in zip(keys, initialdata):
                    if not isinstance(col, self.COLUMN_CLASSES):
                        raise ValueError(
                            f"Values must be one of {self.COLUMN_CLASSES}.")
                    sizes.add(col.size)
                    if len(sizes) > 1:
                        raise ValueError("Input arrays must have equal size.")
                    self._empty = False
                    UserDict.__setitem__(self, key, col)
                    # Update the column index
                    self._columns.append(key)

            # Initial data is invalid.
            else:
                raise ValueError(
                    f"Initialize with dict or list of {self.COLUMN_CLASSES}.")

            # Update the dataframe indices and metadata.
            if len(sizes) > 0:
                self._size = sizes.pop()
            # If the index column was passed in, use that instead of
            # creating a new one.
            if self.data['index'] is None:
                self.data['index'] = ak.arange(0, self._size, 1)

            self.update_size()
Exemple #16
0
 def set(self, key, value):
     UserDict.__setitem__(self, key, value)
Exemple #17
0
 def __setitem__(self, key, value):
   self.parent.updateItem(self.instance, key, value)
   UserDict.__setitem__(self, key, value)
Exemple #18
0
 def __getitem__(self, item):
   if item not in self:
     value = PmfStatDict()
     UserDict.__setitem__(self, item, value)
   return UserDict.__getitem__(self, item)
Exemple #19
0
 def __setitem__(self, key, value):
     data = base64.b64encode(pickle.dumps(value)).decode('ascii')
     return UserDict.__setitem__(self, key, data)
Exemple #20
0
 def __setitem__(self, key, value):
   self.parent.updateItem(self.instance, key, value)
   if value or not self.autoDelete:
     UserDict.__setitem__(self, key, value)
   elif UserDict.__contains__(self, key):
     UserDict.__delitem__(self, key)
Exemple #21
0
 def __setitem__(self, key, value):
     UserDict.__setitem__(self, PBXType.Convert(key), PBXType.Convert(value))
Exemple #22
0
 def __setitem__(self, Key, Value):
     if Key not in self._key_list:
         self._key_list.append(Key)
     IterableUserDict.__setitem__(self, Key, Value)
Exemple #23
0
 def append(self, Sdict2):
     for Key in Sdict2:
         if Key not in self._key_list:
             self._key_list.append(Key)
         IterableUserDict.__setitem__(self, Key, Sdict2[Key])
Exemple #24
0
 def __setitem__(self, name, converter):
     self._validate(name)
     UserDict.__setitem__(self, name, converter)
Exemple #25
0
 def __setitem__(self, key, item):
     UserDict.__setitem__(self, key, item)
     if key not in self._keys: self._keys.append(key)
 def __setitem__(self, key, val):
     if key in self.special_keys:
         raise NotImplementedError("Can't explicitly set {key}".format(key=key))
     return UserDict.__setitem__(self, key, val)
Exemple #27
0
 def insert(self, index, key, item):
     if key not in self._keys:
         self._keys.insert(index, key)
         UserDict.__setitem__(self, key, item)
Exemple #28
0
 def __setitem__(self, key, item):
     UserDict.__setitem__(self, key, item)
     if key not in self._keys: self._keys.append(key)
Exemple #29
0
 def __setitem__(self, key, value):
     UserDict.__setitem__(self, key, value)
     value.channelid = key