4.7.4.2.4. statsmodels.tools.decorators.ResettableCache¶
-
class
statsmodels.tools.decorators.
ResettableCache
(reset=None, **items)[source]¶ Dictionary whose elements mey depend one from another.
If entry B depends on entry A, changing the values of entry A will reset the value of entry B to a default (None); deleteing entry A will delete entry B. The connections between entries are stored in a _resetdict private attribute.
Parameters: reset : dictionary, optional
An optional dictionary, associated a sequence of entries to any key of the object.
items : var, optional
An optional dictionary used to initialize the dictionary
Examples
>>> reset = dict(a=('b',), b=('c',)) >>> cache = resettable_cache(a=0, b=1, c=2, reset=reset) >>> assert_equal(cache, dict(a=0, b=1, c=2))
>>> print("Try resetting a") >>> cache['a'] = 1 >>> assert_equal(cache, dict(a=1, b=None, c=None)) >>> cache['c'] = 2 >>> assert_equal(cache, dict(a=1, b=None, c=2)) >>> cache['b'] = 0 >>> assert_equal(cache, dict(a=1, b=0, c=None))
>>> print("Try deleting b") >>> del(cache['a']) >>> assert_equal(cache, {})
4.7.4.2.4.1. Methods¶
__init__ ([reset]) |
|
clear (() -> None. Remove all items from D.) |
|
copy (() -> a shallow copy of D) |
|
fromkeys (...) |
v defaults to None. |
get ((k[,d]) -> D[k] if k in D, ...) |
|
has_key ((k) -> True if D has a key k, else False) |
|
items (() -> list of D’s (key, value) pairs, ...) |
|
iteritems (() -> an iterator over the (key, ...) |
|
iterkeys (() -> an iterator over the keys of D) |
|
itervalues (...) |
|
keys (() -> list of D’s keys) |
|
pop ((k[,d]) -> v, ...) |
If key is not found, d is returned if given, otherwise KeyError is raised |
popitem (() -> (k, v), ...) |
2-tuple; but raise KeyError if D is empty. |
setdefault ((k[,d]) -> D.get(k,d), ...) |
|
update (([E, ...) |
If E present and has a .keys() method, does: for k in E: D[k] = E[k] |
values (() -> list of D’s values) |
|
viewitems (...) |
|
viewkeys (...) |
|
viewvalues (...) |