text stringlengths 0 828 |
|---|
field_names = set() |
all_fields = [] |
for name in dir(cls): |
fld = getattr(cls, name) |
if fld and isinstance(fld, Field): |
fld.name = name |
all_fields.append(fld) |
field_names.add(name) |
def add_missing_field(name, default='', insert_pos=None): |
if name not in field_names: |
fld = Field(default=default) |
fld.name = name |
all_fields.insert( |
len(all_fields) if insert_pos is None else insert_pos, |
fld |
) |
add_missing_field('id', insert_pos=0) |
add_missing_field('_create_date') |
add_missing_field('_last_update') |
if versioning == VersioningTypes.DELTA_HISTORY: |
add_missing_field('_version_hist', default=list) |
# Things we count on as part of our processing |
cls.__table_name__ = table_name |
cls.__versioning__ = versioning |
cls.__fields__ = all_fields |
# Give them a ctor for free - but make sure we aren't clobbering one |
if not ctor_overridable(cls): |
raise TypeError( |
'Classes with user-supplied __init__ should not be decorated ' |
'with DBObject. Use the setup method' |
) |
cls.__init__ = _auto_init |
# Duck-type the class for our data methods |
cls.get_table_name = classmethod(_get_table_name) |
cls.get_id = _get_id |
cls.set_id = _set_id |
cls.to_data = _to_data |
cls.from_data = classmethod(_from_data) |
cls.index_names = classmethod(_index_names) |
cls.indexes = _indexes |
# Bonus methods they get for using gludb.simple |
cls.get_version_hist = _get_version_hist |
# Register with our abc since we actually implement all necessary |
# functionality |
Storable.register(cls) |
# And now that we're registered, we can also get the database |
# read/write functionality for free |
cls = DatabaseEnabled(cls) |
if versioning == VersioningTypes.DELTA_HISTORY: |
cls.save = _delta_save(cls.save) |
return cls |
return wrapped" |
548,"def get_default_val(self): |
""""""Helper to expand default value (support callables)."""""" |
val = self.default |
while callable(val): |
val = val() |
return val" |
549,"def train(self, data, target, **kwargs): |
"""""" |
Used in the training phase. Override. |
"""""" |
non_predictors = [i.replace("" "", ""_"").lower() for i in list(set(data['team']))] + [""team"", ""next_year_wins""] |
self.column_names = [l for l in list(data.columns) if l not in non_predictors] |
results, folds = self.cross_validate(data, non_predictors, **kwargs) |
self.gather_results(results, folds, data)" |
550,"def compile(self, code): |
"""""" |
Compile a simex code (e.g. <a href=""{{ url }}"">{{ anything }}</a>) to regex. |
Returns regex. |
"""""" |
is_plain_text = True |
compiled_regex = r"""" |
for chunk in self.delimiter_regex().split(code): |
if is_plain_text: |
compiled_regex = compiled_regex + simex_escape(chunk, flexible_whitespace=self._flexible_whitespace) |
else: |
stripped_chunk = chunk.strip() |
if stripped_chunk in self._regexes.keys(): |
compiled_regex = u""{0}{1}"".format( |
compiled_regex, |
self._regexes[stripped_chunk] |
) |
else: |
raise KeyNotFound(""'{0}' not found in keys"") |
is_plain_text = not is_plain_text |
if self._exact: |
compiled_regex = r""^"" + compiled_regex + r""$"" |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.