This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| m2m = M2M() | |
| ch = M2MChain() | |
| gr = M2MGraph() | |
| # TRANSFORMING BETWEEN TYPES | |
| chain(*ch.m2ms) # kind of a copy | |
| chain(ch) # also results in copy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import collections | |
| import functools | |
| def log_methods(cls): | |
| def __init__(self, *a, **kw): | |
| cls.__init__(self, *a, **kw) | |
| self._log = collections.deque(maxlen=100) | |
| def logit(method): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| experimenting with increasingly general notions of indexing | |
| """ | |
| from relativity import M2M | |
| class IndexedTriple(object): | |
| """ | |
| keeps track of "left" to "right" pairs | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> import timeit | |
| >>> LIST = [None] * 10 | |
| >>> countrange = lambda: [1 for i in range(len(LIST))] | |
| >>> countdirect = lambda: [1 for e in LIST] | |
| >>> timeit.timeit(countrange, number=1000) * 1000 | |
| 0.8033999999952357 | |
| >>> timeit.timeit(countdirect, number=1000) * 1000 | |
| 0.5680000000012342 | |
| >>> LIST = [None] * 100 | |
| >>> timeit.timeit(countrange, number=1000) * 1000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| A Schema is a more general container for Python objects. | |
| In addition to tracking relationships between objects, | |
| it can also keep other kind of indexing structures. | |
| Will need a more flexible query object that can represent | |
| comparisons. | |
| NOTE -- not sure if this is really worth it since it only |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import glom | |
| class F(object): | |
| """ | |
| F for filter! | |
| An F object encapsulates boolean comparisons in a similar | |
| manner to SQLAlchemy or Pandas columns. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| _PAIRING = object() # marker | |
| #TODO: rename to Relation | |
| class ManyToMany(object): | |
| """ | |
| a dict-like entity that represents a many-to-many relationship | |
| between two groups of objects | |
| behaves like a dict-of-tuples; also has .inv which is kept |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import attr | |
| import numpy as np | |
| class TimeSampler(object) | |
| ''' | |
| samples from a time indexed series based on time -- pick a random | |
| time within the range of the series; returns the time-delta | |
| and value-delta of the point to the right of the sample with the | |
| point before it | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| line interpolation class for doing a linear regression | |
| ''' | |
| import numpy as np | |
| import pandas | |
| import attr | |
| @attr.s | |
| class Line(object): |