input
stringlengths
11
7.65k
target
stringlengths
22
8.26k
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self, key, child_proxy): try: self._key = int(key) except ValueError: self._key = key self._child_proxy = child_proxy
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def log_row(self, row_category: str, row: List[int]): """Logs a confusion matrix row. Args: row_category: Category to which the row belongs. row: List of integers specifying the values for the row. Raises: ValueError: If row_category is not in the list of categories set in set_categories or size of the row does not match the size of categories. """ if row_category not in self._categories: raise ValueError('Invalid category: {} passed. Expected one of: {}'.\ format(row_category, self._categories)) if len(row) != len(self._categories): raise ValueError('Invalid row. Expected size: {} got: {}'.\ format(len(self._categories), len(row))) self._matrix[self._categories.index(row_category)] = row
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def get(self): return self._child_proxy.get()[self._key]
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def log_cell(self, row_category: str, col_category: str, value: int): """Logs a cell in the confusion matrix. Args: row_category: String representing the name of the row category. col_category: String representing the name of the column category. value: Int value of the cell. Raises: ValueError: If row_category or col_category is not in the list of categories set in set_categories. """ if row_category not in self._categories: raise ValueError('Invalid category: {} passed. Expected one of: {}'.\ format(row_category, self._categories)) if col_category not in self._categories: raise ValueError('Invalid category: {} passed. Expected one of: {}'.\ format(row_category, self._categories)) self._matrix[self._categories.index(row_category)][ self._categories.index(col_category)] = value
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self): self._cache = {} self._bucket_client = None self._param_client = None self._secret_client = None
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def _get_or_create_cached_value(self, key, getter, ttl=None): # happy path try: expiry, value = self._cache[key] except KeyError: pass else: if expiry is None or time.time() < expiry: logger.debug("Key %s from cache", key) return value logger.debug("Cache for key %s has expired", key) # get value value = getter() if ttl: expiry = time.time() + ttl else: expiry = None self._cache[key] = (expiry, value) logger.debug("Set cache for key %s", key) return value
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def getter(): with open(filepath, "r") as f: return f.read()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def getter(): return self._secret_client.get(name)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def getter(): return self._bucket_client.download_to_tmpfile(key)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def getter(): return self._param_client.get(key)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self, path=None, resolver=None): self._path = path or () if not resolver: resolver = Resolver() self._resolver = resolver
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def _make_proxy(self, key, match): proxy_type = match.group("type") key = match.group("key").strip() if proxy_type == "env": proxy = EnvProxy(key) else: proxy = ResolverMethodProxy(self._resolver, proxy_type, key) filters = [f for f in [rf.strip() for rf in match.group("filters").split("|")] if f] for filter_name in filters: if filter_name == "jsondecode": proxy = JSONDecodeFilter(proxy) elif filter_name == "base64decode": proxy = Base64DecodeFilter(proxy) elif filter_name.startswith("element:"): key = filter_name.split(":", 1)[-1] proxy = ElementFilter(key, proxy) else: raise ValueError("Unknown filter %s", filter_name) return proxy
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def _from_python(self, key, value): new_path = self._path + (key,) if isinstance(value, dict): value = self.custom_classes.get(new_path, ConfigDict)(value, new_path) elif isinstance(value, list): value = self.custom_classes.get(new_path, ConfigList)(value, new_path) elif isinstance(value, str): match = self.PROXY_VAR_RE.match(value) if match: value = self._make_proxy(key, match) return value
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def _to_python(self, value): if isinstance(value, Proxy): return value.get() else: return value
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __len__(self): return len(self._collection)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __delitem__(self, key): del self._collection[key]
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __setitem__(self, key, value): self._collection[key] = self._from_python(key, value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def pop(self, key, default=None): value = self._collection.pop(key, default) if isinstance(value, Proxy): value = value.get() return value
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self, config_l, path=None, resolver=None): super().__init__(path=path, resolver=resolver) self._collection = [] for key, value in enumerate(config_l): self._collection.append(self._from_python(str(key), value))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __getitem__(self, key): value = self._collection[key] if isinstance(key, slice): slice_repr = ":".join(str("" if i is None else i) for i in (key.start, key.stop, key.step)) logger.debug("Get /%s[%s] config key", "/".join(self._path), slice_repr) return [self._to_python(item) for item in value] else: logger.debug("Get /%s[%s] config key", "/".join(self._path), key) return self._to_python(value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __iter__(self): for element in self._collection: yield self._to_python(element)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def serialize(self): s = [] for v in self: if isinstance(v, BaseConfig): v = v.serialize() s.append(v) return s
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self, config_d, path=None, resolver=None): super().__init__(path=path, resolver=resolver) self._collection = {} for key, value in config_d.items(): self._collection[key] = self._from_python(key, value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __getitem__(self, key): logger.debug("Get /%s config key", "/".join(self._path + (key,))) value = self._collection[key] return self._to_python(value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def get(self, key, default=None): try: value = self[key] except KeyError: value = self._to_python(default) return value
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __iter__(self): yield from self._collection
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def keys(self): return self._collection.keys()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def values(self): for value in self._collection.values(): yield self._to_python(value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def items(self): for key, value in self._collection.items(): yield key, self._to_python(value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def clear(self): return self._collection.clear()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def setdefault(self, key, default=None): return self._collection.setdefault(key, self._from_python(key, default))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def pop(self, key, default=None): value = self._collection.pop(key, default) return self._to_python(value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def popitem(self): key, value = self._collection.popitem() return key, self._to_python(value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def copy(self): return ConfigDict(self._collection.copy(), path=self._path, resolver=self._resolver)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def update(self, *args, **kwargs): chain = [] for arg in args: if isinstance(arg, dict): iterator = arg.items() else: iterator = arg chain = itertools.chain(chain, iterator) if kwargs: chain = itertools.chain(chain, kwargs.items()) for key, value in iterator: self._collection[key] = self._from_python(key, value)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def __init__(self, p_str): TodoBase.__init__(self, p_str) self.attributes = {}
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def get_organizations(self): legis = Organization('Minnesota Legislature', classification='legislature') upper = Organization('Minnesota Senate', classification='upper', parent_id=legis._id) lower = Organization('Minnesota House of Representatives', classification='lower', parent_id=legis._id) for n in range(1, 68): upper.add_post(label=str(n), role='Senator', division_id='ocd-division/country:us/state:mn/sldu:{}'.format(n)) lower.add_post(label=str(n) + 'A', role='Representative', division_id='ocd-division/country:us/state:mn/sldl:{}a'.format(n)) lower.add_post(label=str(n) + 'B', role='Representative', division_id='ocd-division/country:us/state:mn/sldl:{}b'.format(n)) yield legis yield upper yield lower
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def get_date(self, p_tag): """ Given a date tag, return a date object. """ string = self.tag_value(p_tag) result = None try: result = date_string_to_date(string) if string else None except ValueError: pass return result
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def start_date(self): """ Returns a date object of the todo's start date. """ return self.get_date(config().tag_start())
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def due_date(self): """ Returns a date object of the todo's due date. """ return self.get_date(config().tag_due())
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def is_active(self): """ Returns True when the start date is today or in the past and the task has not yet been completed. """ start = self.start_date() return not self.is_completed() and (not start or start <= date.today())
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def is_overdue(self): """ Returns True when the due date is in the past and the task has not yet been completed. """ return not self.is_completed() and self.days_till_due() < 0
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def days_till_due(self): """ Returns the number of days till the due date. Returns a negative number of days when the due date is in the past. Returns 0 when the task has no due date. """ due = self.due_date() if due: diff = due - date.today() return diff.days return 0
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def main(self): UI.OpenDialog( VBox( Heading("This Is a Heading."), Label("This is a Label."), PushButton("&OK") ) ) UI.UserInput() UI.CloseDialog()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): df2 = df[['A']] df2['A'] += 10 return df2.A, df.A
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_scheme(): # does not raise NotImplementedError UrlPath('/dev/null').touch()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): S1 = pd.Series(np.ones(n)) S2 = pd.Series(np.random.ranf(n)) df = pd.DataFrame({'A': S1, 'B': S2}) return df.A.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_scheme_not_supported(): with pytest.raises(NotImplementedError): UrlPath('http:///tmp/test').touch()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): return df['A'][df['B']].values
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_scheme_not_listed(): with pytest.raises(NotImplementedError): UrlPath('test:///tmp/test').touch()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): A = np.array([1., 2., 3.]) A[0] = np.nan df = pd.DataFrame({'A': A}) B = df.A.fillna(5.0) return B.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_file_additional(): assert UrlPath('.').resolve() == UrlPath.cwd()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): A = np.array([1., 2., 3.]) A[0] = np.nan df = pd.DataFrame({'A': A}) df.A.fillna(5.0, inplace=True) return df.A.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): A = np.array([1., 2., 3.]) A[0] = np.nan df = pd.DataFrame({'A': A}) return df.A.mean()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): A = np.array([1., 2., 3.]) A[0] = 4.0 df = pd.DataFrame({'A': A}) return df.A.var()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): A = np.array([1., 2., 3.]) A[0] = 4.0 df = pd.DataFrame({'A': A}) return df.A.std()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(n)}) df['B'] = df.A.map(lambda a: 2 * a) return df.B.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): df['B'] = df.A.map(lambda a: 2 * a) return
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)}) Ac = df.A.cumsum() return Ac.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)}) df.A.fillna(5.0, inplace=True) DF = df.A.fillna(5.0) s = DF.sum() m = df.A.mean() v = df.A.var() t = df.A.std() Ac = df.A.cumsum() return Ac.sum() + s + m + v + t
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(0, n, 1, np.float64)}) return df.A.quantile(.25)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(0, n, 1, np.float32)}) df.A[0:100] = np.nan df.A[200:331] = np.nan return df.A.quantile(.25)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(0, n, 1, np.int32)}) return df.A.quantile(.25)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(A): df = pd.DataFrame({'A': A}) return df.A.quantile(.25)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(n)}) df.A[2] = 0 return df.A.nunique()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): df = pq.read_table('example.parquet').to_pandas() return df.four.nunique()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': ['aa', 'bb', 'aa', 'cc', 'cc']}) return df.A.nunique()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): df = pq.read_table('example.parquet').to_pandas() return df.two.nunique()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): df = pq.read_table('example.parquet').to_pandas() return (df.four.unique() == 3.0).sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): df = pq.read_table('example.parquet').to_pandas() return (df.two.unique() == 'foo').sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(0, n, 1, np.float64)}) return df.A.describe()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): A = StringArray(['ABC', 'BB', 'ADEF']) df = pd.DataFrame({'A': A}) B = df.A.str.contains('AB*', regex=True) return B.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): A = StringArray(['ABC', 'BB', 'ADEF']) df = pd.DataFrame({'A': A}) B = df.A.str.contains('BB', regex=False) return B.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): return df.A.str.replace('AB*', 'EE', regex=True)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): return df.A.str.replace('AB', 'EE', regex=False)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): B = df.A.str.replace('AB*', 'EE', regex=True) return B
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): return df.A.str.split()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): B = df.A.str.split(',') df2 = pd.DataFrame({'B': B}) return df2[df2.B.str.len() > 1]
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): return df.A.iloc[0]
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): B = df.A.str.split(',') C = pd.to_numeric(B.str.get(1), errors='coerce') return C
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): A = df.A.str.split(',') return pd.Series(list(itertools.chain(*A)))
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): A = df.A.str.split(',') B = pd.Series(list(itertools.chain(*A))) return B
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): B = pd.to_numeric(df.A, errors='coerce') return B
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(n), 'B': np.arange(n) + 1.0}) df1 = df[df.A > 5] return len(df1.B)
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(n), 'B': np.random.ranf(n)}) Ac = df.A.rolling(3).sum() return Ac.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl_2(n): df = pd.DataFrame({'A': np.arange(n) + 1.0, 'B': np.random.ranf(n)}) Ac = df.A.rolling(7).sum() return Ac.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)}) df['moving average'] = df.A.rolling(window=5, center=True).mean() return df['moving average'].sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.ones(n), 'B': np.random.ranf(n)}) Ac = df.A.rolling(3, center=True).apply(lambda a: a[0] + 2 * a[1] + a[2]) return Ac.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(n) + 1.0, 'B': np.random.ranf(n)}) Ac = df.A.shift(1) return Ac.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df = pd.DataFrame({'A': np.arange(n) + 1.0, 'B': np.random.ranf(n)}) Ac = df.A.pct_change(1) return Ac.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): return df.B.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): C = df.B == 'two' return C.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(df): return df.B.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df1 = pd.DataFrame({'key1': np.arange(n), 'A': np.arange(n) + 1.0}) df2 = pd.DataFrame({'key2': n - np.arange(n), 'A': n + np.arange(n) + 1.0}) df3 = pd.concat([df1, df2]) return df3.A.sum() + df3.key2.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): df1 = pq.read_table('example.parquet').to_pandas() df2 = pq.read_table('example.parquet').to_pandas() A3 = pd.concat([df1, df2]) return (A3.two == 'foo').sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(n): df1 = pd.DataFrame({'key1': np.arange(n), 'A': np.arange(n) + 1.0}) df2 = pd.DataFrame({'key2': n - np.arange(n), 'A': n + np.arange(n) + 1.0}) A3 = pd.concat([df1.A, df2.A]) return A3.sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(): df1 = pq.read_table('example.parquet').to_pandas() df2 = pq.read_table('example.parquet').to_pandas() A3 = pd.concat([df1.two, df2.two]) return (A3 == 'foo').sum()
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(nsyms): max_num_days = 100 all_res = 0.0 for i in sdc.prange(nsyms): s_open = 20 * np.ones(max_num_days) s_low = 28 * np.ones(max_num_days) s_close = 19 * np.ones(max_num_days) df = pd.DataFrame({'Open': s_open, 'Low': s_low, 'Close': s_close}) df['Stdev'] = df['Close'].rolling(window=90).std() df['Moving Average'] = df['Close'].rolling(window=20).mean() df['Criteria1'] = (df['Open'] - df['Low'].shift(1)) < -df['Stdev'] df['Criteria2'] = df['Open'] > df['Moving Average'] df['BUY'] = df['Criteria1'] & df['Criteria2'] df['Pct Change'] = (df['Close'] - df['Open']) / df['Open'] df['Rets'] = df['Pct Change'][df['BUY']] all_res += df['Rets'].mean() return all_res
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_impl(A, B): df = pd.DataFrame({'A': A, 'B': B}) df2 = df.groupby('A', as_index=False)['B'].sum() # TODO: fix handling of df setitem to force match of array dists # probably with a new node that is appended to the end of basic block # df2['C'] = np.full(len(df2.B), 3, np.int8) # TODO: full_like for Series df2['C'] = np.full_like(df2.B.values, 3, np.int8) return df2
def emit(self, level, message): raise NotImplementedError('Please implement an emit method')
def test_both(): """Both f and g.""" p = are.above(2) & are.below(4) ps = [p(x) for x in range(1, 6)] assert ps == [False, False, True, False, False]