Python collections.OrderedDict.__getitem__() Examples
The following are 30
code examples of collections.OrderedDict.__getitem__().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
collections.OrderedDict
, or try the search function
.
Example #1
Source File: table.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __getitem__(self, item): """Get items from a TableColumns object. :: tc = TableColumns(cols=[Column(name='a'), Column(name='b'), Column(name='c')]) tc['a'] # Column('a') tc[1] # Column('b') tc['a', 'b'] # <TableColumns names=('a', 'b')> tc[1:3] # <TableColumns names=('b', 'c')> """ if isinstance(item, str): return OrderedDict.__getitem__(self, item) elif isinstance(item, (int, np.integer)): return self.values()[item] elif (isinstance(item, np.ndarray) and item.shape == () and item.dtype.kind == 'i'): return self.values()[item.item()] elif isinstance(item, tuple): return self.__class__([self[x] for x in item]) elif isinstance(item, slice): return self.__class__([self[x] for x in list(self)[item]]) else: raise IndexError('Illegal key or index value for {} object' .format(self.__class__.__name__))
Example #2
Source File: extract_scenario_tree.py From EnergyPATHWAYS with MIT License | 5 votes |
def __getitem__(self, key): try: return OrderedDict.__getitem__(self, key) except KeyError: return self.__missing__(key)
Example #3
Source File: data_structures.py From devito with MIT License | 5 votes |
def __getitem__(self, key): if isinstance(key, (int, slice)): return super(EnrichedTuple, self).__getitem__(key) else: return self.__getitem_hook__(key)
Example #4
Source File: data_structures.py From devito with MIT License | 5 votes |
def __getitem__(self, key): try: return OrderedDict.__getitem__(self, key) except KeyError: return self.__missing__(key)
Example #5
Source File: data_structures.py From devito with MIT License | 5 votes |
def __getitem__(self, key): return self._dict[key]
Example #6
Source File: utils.py From uroboroSQL-formatter with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __getitem__(self, key, *args, **kwargs): # Get the key and remove it from the cache, or raise KeyError value = OrderedDict.__getitem__(self, key) del self[key] # Insert the (key, value) pair on the front of the cache OrderedDict.__setitem__(self, key, value) # Return the value from the cache return value
Example #7
Source File: cryptoengine.py From joinmarket-clientserver with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, item): e = OrderedDict.__getitem__(self, item) del self[item] OrderedDict.__setitem__(self, item, e) return e
Example #8
Source File: pgcollections.py From soapy with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, item): if type(item) is list: return self.reverse[item[0]] else: return dict.__getitem__(self, item)
Example #9
Source File: pgcollections.py From soapy with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, attr): self.lock() try: val = dict.__getitem__(self, attr) finally: self.unlock() return val
Example #10
Source File: pgcollections.py From soapy with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, attr): self.lock() try: val = list.__getitem__(self, attr) finally: self.unlock() return val
Example #11
Source File: pgcollections.py From soapy with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, key): kl = key.lower() if kl not in self.keyMap: raise KeyError(key) return OrderedDict.__getitem__(self, self.keyMap[kl])
Example #12
Source File: utils.py From graphqllib with MIT License | 5 votes |
def __getitem__(self, key): try: return OrderedDict.__getitem__(self, key) except KeyError: return self.__missing__(key)
Example #13
Source File: pgcollections.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, item): if type(item) is list: return self.reverse[item[0]] else: return dict.__getitem__(self, item)
Example #14
Source File: pgcollections.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, attr): self.lock() try: val = dict.__getitem__(self, attr) finally: self.unlock() return val
Example #15
Source File: pgcollections.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, attr): self.lock() try: val = list.__getitem__(self, attr) finally: self.unlock() return val
Example #16
Source File: pgcollections.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, key): kl = key.lower() if kl not in self.keyMap: raise KeyError(key) return OrderedDict.__getitem__(self, self.keyMap[kl])
Example #17
Source File: idi.py From fits2hdf with MIT License | 5 votes |
def __getitem__(self, item): """Get items from a TableColumns object.""" if isinstance(item, six.string_types): try: return OrderedDict.__getitem__(self, item) except KeyError: try: return OrderedDict.__getitem__(self, item.lower()) except KeyError: return OrderedDict.__getitem__(self, item.upper()) elif isinstance(item, int): return self.values()[item] elif isinstance(item, tuple): return self.__class__([self[x] for x in item]) elif isinstance(item, slice): return self.__class__([self[x] for x in list(self)[item]]) else: raise IndexError('Illegal key or index value for {} object' .format(self.__class__.__name__))
Example #18
Source File: table.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __getitem__(self, item): if isinstance(item, str): return self.columns[item] elif isinstance(item, (int, np.integer)): return self.Row(self, item) elif (isinstance(item, np.ndarray) and item.shape == () and item.dtype.kind == 'i'): return self.Row(self, item.item()) elif self._is_list_or_tuple_of_str(item): out = self.__class__([self[x] for x in item], copy_indices=self._copy_indices) out._groups = groups.TableGroups(out, indices=self.groups._indices, keys=self.groups._keys) out.meta = self.meta.copy() # Shallow copy for meta return out elif ((isinstance(item, np.ndarray) and item.size == 0) or (isinstance(item, (tuple, list)) and not item)): # If item is an empty array/list/tuple then return the table with no rows return self._new_from_slice([]) elif (isinstance(item, slice) or isinstance(item, np.ndarray) or isinstance(item, list) or isinstance(item, tuple) and all(isinstance(x, np.ndarray) for x in item)): # here for the many ways to give a slice; a tuple of ndarray # is produced by np.where, as in t[np.where(t['a'] > 2)] # For all, a new table is constructed with slice of all columns return self._new_from_slice(item) else: raise ValueError('Illegal type {} for table item access' .format(type(item)))
Example #19
Source File: table.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __len__(self): # For performance reasons (esp. in Row) cache the first column name # and use that subsequently for the table length. If might not be # available yet or the column might be gone now, in which case # try again in the except block. try: return len(OrderedDict.__getitem__(self.columns, self._first_colname)) except (AttributeError, KeyError): if len(self.columns) == 0: return 0 # Get the first column name self._first_colname = next(iter(self.columns)) return len(self.columns[self._first_colname])
Example #20
Source File: row.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __getitem__(self, item): try: # Try the most common use case of accessing a single column in the Row. # Bypass the TableColumns __getitem__ since that does more testing # and allows a list of tuple or str, which is not the right thing here. out = OrderedDict.__getitem__(self._table.columns, item)[self._index] except (KeyError, TypeError): if self._table._is_list_or_tuple_of_str(item): cols = [self._table[name] for name in item] out = self._table.__class__(cols, copy=False)[self._index] else: # This is only to raise an exception out = self._table.columns[item][self._index] return out
Example #21
Source File: _lru_cache.py From rich with MIT License | 5 votes |
def __getitem__(self: Dict[CacheKey, CacheValue], key: CacheKey) -> CacheValue: """Gets the item, but also makes it most recent.""" value: CacheValue = OrderedDict.__getitem__(self, key) OrderedDict.__delitem__(self, key) OrderedDict.__setitem__(self, key, value) return value
Example #22
Source File: pgcollections.py From tf-pose with Apache License 2.0 | 5 votes |
def __getitem__(self, item): if type(item) is list: return self.reverse[item[0]] else: return dict.__getitem__(self, item)
Example #23
Source File: pgcollections.py From tf-pose with Apache License 2.0 | 5 votes |
def __getitem__(self, attr): self.lock() try: val = dict.__getitem__(self, attr) finally: self.unlock() return val
Example #24
Source File: pgcollections.py From tf-pose with Apache License 2.0 | 5 votes |
def __getitem__(self, attr): self.lock() try: val = list.__getitem__(self, attr) finally: self.unlock() return val
Example #25
Source File: pgcollections.py From tf-pose with Apache License 2.0 | 5 votes |
def __getitem__(self, key): kl = key.lower() if kl not in self.keyMap: raise KeyError(key) return OrderedDict.__getitem__(self, self.keyMap[kl])
Example #26
Source File: __init__.py From D-VAE with MIT License | 5 votes |
def __getitem__(self, key): try: return OrderedDict.__getitem__(self, key) except KeyError: return self.__missing__(key)
Example #27
Source File: defaultOrderedDict.py From Comparative-Annotation-Toolkit with Apache License 2.0 | 5 votes |
def __getitem__(self, key): try: return OrderedDict.__getitem__(self, key) except KeyError: return self.__missing__(key)
Example #28
Source File: ordereddict.py From mappyfile with MIT License | 5 votes |
def __getitem__(self, key): key = key.lower() # all keys should be lower-case to make editing easier try: return OrderedDict.__getitem__(self, key) except KeyError: return self.__missing__(key)
Example #29
Source File: ordereddict.py From mappyfile with MIT License | 5 votes |
def __getitem__(self, key): return super(CaseInsensitiveOrderedDict, self).__getitem__(self.__class__._k(key))
Example #30
Source File: utils.py From ssbio with MIT License | 5 votes |
def __getitem__(self, key): try: return OrderedDict.__getitem__(self, key) except KeyError: return self.__missing__(key)