repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
datajoint/datajoint-python
datajoint/declare.py
compile_foreign_key
def compile_foreign_key(line, context, attributes, primary_key, attr_sql, foreign_key_sql, index_sql): """ :param line: a line from a table definition :param context: namespace containing referenced objects :param attributes: list of attribute names already in the declaration -- to be updated by this fu...
python
def compile_foreign_key(line, context, attributes, primary_key, attr_sql, foreign_key_sql, index_sql): """ :param line: a line from a table definition :param context: namespace containing referenced objects :param attributes: list of attribute names already in the declaration -- to be updated by this fu...
[ "def", "compile_foreign_key", "(", "line", ",", "context", ",", "attributes", ",", "primary_key", ",", "attr_sql", ",", "foreign_key_sql", ",", "index_sql", ")", ":", "# Parse and validate", "from", ".", "table", "import", "Table", "from", ".", "expression", "im...
:param line: a line from a table definition :param context: namespace containing referenced objects :param attributes: list of attribute names already in the declaration -- to be updated by this function :param primary_key: None if the current foreign key is made from the dependent section. Otherwise it is ...
[ ":", "param", "line", ":", "a", "line", "from", "a", "table", "definition", ":", "param", "context", ":", "namespace", "containing", "referenced", "objects", ":", "param", "attributes", ":", "list", "of", "attribute", "names", "already", "in", "the", "declar...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/declare.py#L81-L189
datajoint/datajoint-python
datajoint/declare.py
declare
def declare(full_table_name, definition, context): """ Parse declaration and create new SQL table accordingly. :param full_table_name: full name of the table :param definition: DataJoint table definition :param context: dictionary of objects that might be referred to in the table. """ tabl...
python
def declare(full_table_name, definition, context): """ Parse declaration and create new SQL table accordingly. :param full_table_name: full name of the table :param definition: DataJoint table definition :param context: dictionary of objects that might be referred to in the table. """ tabl...
[ "def", "declare", "(", "full_table_name", ",", "definition", ",", "context", ")", ":", "table_name", "=", "full_table_name", ".", "strip", "(", "'`'", ")", ".", "split", "(", "'.'", ")", "[", "1", "]", "if", "len", "(", "table_name", ")", ">", "MAX_TAB...
Parse declaration and create new SQL table accordingly. :param full_table_name: full name of the table :param definition: DataJoint table definition :param context: dictionary of objects that might be referred to in the table.
[ "Parse", "declaration", "and", "create", "new", "SQL", "table", "accordingly", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/declare.py#L192-L245
datajoint/datajoint-python
datajoint/declare.py
compile_attribute
def compile_attribute(line, in_key, foreign_key_sql): """ Convert attribute definition from DataJoint format to SQL :param line: attribution line :param in_key: set to True if attribute is in primary key set :param foreign_key_sql: :returns: (name, sql, is_external) -- attribute name and sql co...
python
def compile_attribute(line, in_key, foreign_key_sql): """ Convert attribute definition from DataJoint format to SQL :param line: attribution line :param in_key: set to True if attribute is in primary key set :param foreign_key_sql: :returns: (name, sql, is_external) -- attribute name and sql co...
[ "def", "compile_attribute", "(", "line", ",", "in_key", ",", "foreign_key_sql", ")", ":", "try", ":", "match", "=", "attribute_parser", ".", "parseString", "(", "line", "+", "'#'", ",", "parseAll", "=", "True", ")", "except", "pp", ".", "ParseException", "...
Convert attribute definition from DataJoint format to SQL :param line: attribution line :param in_key: set to True if attribute is in primary key set :param foreign_key_sql: :returns: (name, sql, is_external) -- attribute name and sql code for its declaration
[ "Convert", "attribute", "definition", "from", "DataJoint", "format", "to", "SQL" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/declare.py#L255-L325
datajoint/datajoint-python
datajoint/jobs.py
JobTable.reserve
def reserve(self, table_name, key): """ Reserve a job for computation. When a job is reserved, the job table contains an entry for the job key, identified by its hash. When jobs are completed, the entry is removed. :param table_name: `database`.`table_name` :param key: the dict ...
python
def reserve(self, table_name, key): """ Reserve a job for computation. When a job is reserved, the job table contains an entry for the job key, identified by its hash. When jobs are completed, the entry is removed. :param table_name: `database`.`table_name` :param key: the dict ...
[ "def", "reserve", "(", "self", ",", "table_name", ",", "key", ")", ":", "job", "=", "dict", "(", "table_name", "=", "table_name", ",", "key_hash", "=", "key_hash", "(", "key", ")", ",", "status", "=", "'reserved'", ",", "host", "=", "platform", ".", ...
Reserve a job for computation. When a job is reserved, the job table contains an entry for the job key, identified by its hash. When jobs are completed, the entry is removed. :param table_name: `database`.`table_name` :param key: the dict of the job's primary key :return: True if reserv...
[ "Reserve", "a", "job", "for", "computation", ".", "When", "a", "job", "is", "reserved", "the", "job", "table", "contains", "an", "entry", "for", "the", "job", "key", "identified", "by", "its", "hash", ".", "When", "jobs", "are", "completed", "the", "entr...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/jobs.py#L61-L82
datajoint/datajoint-python
datajoint/jobs.py
JobTable.complete
def complete(self, table_name, key): """ Log a completed job. When a job is completed, its reservation entry is deleted. :param table_name: `database`.`table_name` :param key: the dict of the job's primary key """ job_key = dict(table_name=table_name, key_hash=key_hash(k...
python
def complete(self, table_name, key): """ Log a completed job. When a job is completed, its reservation entry is deleted. :param table_name: `database`.`table_name` :param key: the dict of the job's primary key """ job_key = dict(table_name=table_name, key_hash=key_hash(k...
[ "def", "complete", "(", "self", ",", "table_name", ",", "key", ")", ":", "job_key", "=", "dict", "(", "table_name", "=", "table_name", ",", "key_hash", "=", "key_hash", "(", "key", ")", ")", "(", "self", "&", "job_key", ")", ".", "delete_quick", "(", ...
Log a completed job. When a job is completed, its reservation entry is deleted. :param table_name: `database`.`table_name` :param key: the dict of the job's primary key
[ "Log", "a", "completed", "job", ".", "When", "a", "job", "is", "completed", "its", "reservation", "entry", "is", "deleted", ".", ":", "param", "table_name", ":", "database", ".", "table_name", ":", "param", "key", ":", "the", "dict", "of", "the", "job", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/jobs.py#L84-L91
datajoint/datajoint-python
datajoint/jobs.py
JobTable.error
def error(self, table_name, key, error_message, error_stack=None): """ Log an error message. The job reservation is replaced with an error entry. if an error occurs, leave an entry describing the problem :param table_name: `database`.`table_name` :param key: the dict of the job'...
python
def error(self, table_name, key, error_message, error_stack=None): """ Log an error message. The job reservation is replaced with an error entry. if an error occurs, leave an entry describing the problem :param table_name: `database`.`table_name` :param key: the dict of the job'...
[ "def", "error", "(", "self", ",", "table_name", ",", "key", ",", "error_message", ",", "error_stack", "=", "None", ")", ":", "if", "len", "(", "error_message", ")", ">", "ERROR_MESSAGE_LENGTH", ":", "error_message", "=", "error_message", "[", ":", "ERROR_MES...
Log an error message. The job reservation is replaced with an error entry. if an error occurs, leave an entry describing the problem :param table_name: `database`.`table_name` :param key: the dict of the job's primary key :param error_message: string error message :param error_s...
[ "Log", "an", "error", "message", ".", "The", "job", "reservation", "is", "replaced", "with", "an", "error", "entry", ".", "if", "an", "error", "occurs", "leave", "an", "entry", "describing", "the", "problem", ":", "param", "table_name", ":", "database", "....
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/jobs.py#L93-L115
datajoint/datajoint-python
datajoint/schema.py
ordered_dir
def ordered_dir(klass): """ List (most) attributes of the class including inherited ones, similar to `dir` build-in function, but respects order of attribute declaration as much as possible. This becomes unnecessary in Python 3.6+ as dicts became ordered. :param klass: class to list members for ...
python
def ordered_dir(klass): """ List (most) attributes of the class including inherited ones, similar to `dir` build-in function, but respects order of attribute declaration as much as possible. This becomes unnecessary in Python 3.6+ as dicts became ordered. :param klass: class to list members for ...
[ "def", "ordered_dir", "(", "klass", ")", ":", "attr_list", "=", "list", "(", ")", "for", "c", "in", "reversed", "(", "klass", ".", "mro", "(", ")", ")", ":", "attr_list", ".", "extend", "(", "e", "for", "e", "in", "(", "c", ".", "_ordered_class_mem...
List (most) attributes of the class including inherited ones, similar to `dir` build-in function, but respects order of attribute declaration as much as possible. This becomes unnecessary in Python 3.6+ as dicts became ordered. :param klass: class to list members for :return: a list of attributes declar...
[ "List", "(", "most", ")", "attributes", "of", "the", "class", "including", "inherited", "ones", "similar", "to", "dir", "build", "-", "in", "function", "but", "respects", "order", "of", "attribute", "declaration", "as", "much", "as", "possible", ".", "This",...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L20-L33
datajoint/datajoint-python
datajoint/schema.py
create_virtual_module
def create_virtual_module(module_name, schema_name, create_schema=False, create_tables=False, connection=None): """ Creates a python module with the given name from the name of a schema on the server and automatically adds classes to it corresponding to the tables in the schema. :param module_name: dis...
python
def create_virtual_module(module_name, schema_name, create_schema=False, create_tables=False, connection=None): """ Creates a python module with the given name from the name of a schema on the server and automatically adds classes to it corresponding to the tables in the schema. :param module_name: dis...
[ "def", "create_virtual_module", "(", "module_name", ",", "schema_name", ",", "create_schema", "=", "False", ",", "create_tables", "=", "False", ",", "connection", "=", "None", ")", ":", "module", "=", "types", ".", "ModuleType", "(", "module_name", ")", "_sche...
Creates a python module with the given name from the name of a schema on the server and automatically adds classes to it corresponding to the tables in the schema. :param module_name: displayed module name :param schema_name: name of the database in mysql :param create_schema: if True, create the schem...
[ "Creates", "a", "python", "module", "with", "the", "given", "name", "from", "the", "name", "of", "a", "schema", "on", "the", "server", "and", "automatically", "adds", "classes", "to", "it", "corresponding", "to", "the", "tables", "in", "the", "schema", "."...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L241-L256
datajoint/datajoint-python
datajoint/schema.py
Schema.size_on_disk
def size_on_disk(self): """ :return: size of the entire schema in bytes """ return int(self.connection.query( """ SELECT SUM(data_length + index_length) FROM information_schema.tables WHERE table_schema='{db}' """.format(db=self.database))....
python
def size_on_disk(self): """ :return: size of the entire schema in bytes """ return int(self.connection.query( """ SELECT SUM(data_length + index_length) FROM information_schema.tables WHERE table_schema='{db}' """.format(db=self.database))....
[ "def", "size_on_disk", "(", "self", ")", ":", "return", "int", "(", "self", ".", "connection", ".", "query", "(", "\"\"\"\n SELECT SUM(data_length + index_length)\n FROM information_schema.tables WHERE table_schema='{db}'\n \"\"\"", ".", "format", ...
:return: size of the entire schema in bytes
[ ":", "return", ":", "size", "of", "the", "entire", "schema", "in", "bytes" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L92-L100
datajoint/datajoint-python
datajoint/schema.py
Schema.spawn_missing_classes
def spawn_missing_classes(self, context=None): """ Creates the appropriate python user relation classes from tables in the schema and places them in the context. :param context: alternative context to place the missing classes into, e.g. locals() """ if context is None: ...
python
def spawn_missing_classes(self, context=None): """ Creates the appropriate python user relation classes from tables in the schema and places them in the context. :param context: alternative context to place the missing classes into, e.g. locals() """ if context is None: ...
[ "def", "spawn_missing_classes", "(", "self", ",", "context", "=", "None", ")", ":", "if", "context", "is", "None", ":", "if", "self", ".", "context", "is", "not", "None", ":", "context", "=", "self", ".", "context", "else", ":", "# if context is missing, u...
Creates the appropriate python user relation classes from tables in the schema and places them in the context. :param context: alternative context to place the missing classes into, e.g. locals()
[ "Creates", "the", "appropriate", "python", "user", "relation", "classes", "from", "tables", "in", "the", "schema", "and", "places", "them", "in", "the", "context", ".", ":", "param", "context", ":", "alternative", "context", "to", "place", "the", "missing", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L102-L144
datajoint/datajoint-python
datajoint/schema.py
Schema.drop
def drop(self, force=False): """ Drop the associated schema if it exists """ if not self.exists: logger.info("Schema named `{database}` does not exist. Doing nothing.".format(database=self.database)) elif (not config['safemode'] or force or ...
python
def drop(self, force=False): """ Drop the associated schema if it exists """ if not self.exists: logger.info("Schema named `{database}` does not exist. Doing nothing.".format(database=self.database)) elif (not config['safemode'] or force or ...
[ "def", "drop", "(", "self", ",", "force", "=", "False", ")", ":", "if", "not", "self", ".", "exists", ":", "logger", ".", "info", "(", "\"Schema named `{database}` does not exist. Doing nothing.\"", ".", "format", "(", "database", "=", "self", ".", "database",...
Drop the associated schema if it exists
[ "Drop", "the", "associated", "schema", "if", "it", "exists" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L146-L161
datajoint/datajoint-python
datajoint/schema.py
Schema.exists
def exists(self): """ :return: true if the associated schema exists on the server """ cur = self.connection.query("SHOW DATABASES LIKE '{database}'".format(database=self.database)) return cur.rowcount > 0
python
def exists(self): """ :return: true if the associated schema exists on the server """ cur = self.connection.query("SHOW DATABASES LIKE '{database}'".format(database=self.database)) return cur.rowcount > 0
[ "def", "exists", "(", "self", ")", ":", "cur", "=", "self", ".", "connection", ".", "query", "(", "\"SHOW DATABASES LIKE '{database}'\"", ".", "format", "(", "database", "=", "self", ".", "database", ")", ")", "return", "cur", ".", "rowcount", ">", "0" ]
:return: true if the associated schema exists on the server
[ ":", "return", ":", "true", "if", "the", "associated", "schema", "exists", "on", "the", "server" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L164-L169
datajoint/datajoint-python
datajoint/schema.py
Schema.process_relation_class
def process_relation_class(self, relation_class, context, assert_declared=False): """ assign schema properties to the relation class and declare the table """ relation_class.database = self.database relation_class._connection = self.connection relation_class._heading = He...
python
def process_relation_class(self, relation_class, context, assert_declared=False): """ assign schema properties to the relation class and declare the table """ relation_class.database = self.database relation_class._connection = self.connection relation_class._heading = He...
[ "def", "process_relation_class", "(", "self", ",", "relation_class", ",", "context", ",", "assert_declared", "=", "False", ")", ":", "relation_class", ".", "database", "=", "self", ".", "database", "relation_class", ".", "_connection", "=", "self", ".", "connect...
assign schema properties to the relation class and declare the table
[ "assign", "schema", "properties", "to", "the", "relation", "class", "and", "declare", "the", "table" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L171-L197
datajoint/datajoint-python
datajoint/schema.py
Schema.jobs
def jobs(self): """ schema.jobs provides a view of the job reservation table for the schema :return: jobs table """ if self._jobs is None: self._jobs = JobTable(self.connection, self.database) return self._jobs
python
def jobs(self): """ schema.jobs provides a view of the job reservation table for the schema :return: jobs table """ if self._jobs is None: self._jobs = JobTable(self.connection, self.database) return self._jobs
[ "def", "jobs", "(", "self", ")", ":", "if", "self", ".", "_jobs", "is", "None", ":", "self", ".", "_jobs", "=", "JobTable", "(", "self", ".", "connection", ",", "self", ".", "database", ")", "return", "self", ".", "_jobs" ]
schema.jobs provides a view of the job reservation table for the schema :return: jobs table
[ "schema", ".", "jobs", "provides", "a", "view", "of", "the", "job", "reservation", "table", "for", "the", "schema", ":", "return", ":", "jobs", "table" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L221-L228
datajoint/datajoint-python
datajoint/schema.py
Schema.external_table
def external_table(self): """ schema.external provides a view of the external hash table for the schema :return: external table """ if self._external is None: self._external = ExternalTable(self.connection, self.database) return self._external
python
def external_table(self): """ schema.external provides a view of the external hash table for the schema :return: external table """ if self._external is None: self._external = ExternalTable(self.connection, self.database) return self._external
[ "def", "external_table", "(", "self", ")", ":", "if", "self", ".", "_external", "is", "None", ":", "self", ".", "_external", "=", "ExternalTable", "(", "self", ".", "connection", ",", "self", ".", "database", ")", "return", "self", ".", "_external" ]
schema.external provides a view of the external hash table for the schema :return: external table
[ "schema", ".", "external", "provides", "a", "view", "of", "the", "external", "hash", "table", "for", "the", "schema", ":", "return", ":", "external", "table" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/schema.py#L231-L238
datajoint/datajoint-python
datajoint/table.py
lookup_class_name
def lookup_class_name(name, context, depth=3): """ given a table name in the form `schema_name`.`table_name`, find its class in the context. :param name: `schema_name`.`table_name` :param context: dictionary representing the namespace :param depth: search depth into imported modules, helps avoid inf...
python
def lookup_class_name(name, context, depth=3): """ given a table name in the form `schema_name`.`table_name`, find its class in the context. :param name: `schema_name`.`table_name` :param context: dictionary representing the namespace :param depth: search depth into imported modules, helps avoid inf...
[ "def", "lookup_class_name", "(", "name", ",", "context", ",", "depth", "=", "3", ")", ":", "# breadth-first search", "nodes", "=", "[", "dict", "(", "context", "=", "context", ",", "context_name", "=", "''", ",", "depth", "=", "depth", ")", "]", "while",...
given a table name in the form `schema_name`.`table_name`, find its class in the context. :param name: `schema_name`.`table_name` :param context: dictionary representing the namespace :param depth: search depth into imported modules, helps avoid infinite recursion. :return: class name found in the conte...
[ "given", "a", "table", "name", "in", "the", "form", "schema_name", ".", "table_name", "find", "its", "class", "in", "the", "context", ".", ":", "param", "name", ":", "schema_name", ".", "table_name", ":", "param", "context", ":", "dictionary", "representing"...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L571-L604
datajoint/datajoint-python
datajoint/table.py
Table.heading
def heading(self): """ Returns the table heading. If the table is not declared, attempts to declare it and return heading. :return: table heading """ if self._heading is None: self._heading = Heading() # instance-level heading if not self._heading: # lazy lo...
python
def heading(self): """ Returns the table heading. If the table is not declared, attempts to declare it and return heading. :return: table heading """ if self._heading is None: self._heading = Heading() # instance-level heading if not self._heading: # lazy lo...
[ "def", "heading", "(", "self", ")", ":", "if", "self", ".", "_heading", "is", "None", ":", "self", ".", "_heading", "=", "Heading", "(", ")", "# instance-level heading", "if", "not", "self", ".", "_heading", ":", "# lazy loading of heading", "if", "self", ...
Returns the table heading. If the table is not declared, attempts to declare it and return heading. :return: table heading
[ "Returns", "the", "table", "heading", ".", "If", "the", "table", "is", "not", "declared", "attempts", "to", "declare", "it", "and", "return", "heading", ".", ":", "return", ":", "table", "heading" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L42-L56
datajoint/datajoint-python
datajoint/table.py
Table.declare
def declare(self, context=None): """ Use self.definition to declare the table in the schema. """ try: sql, uses_external = declare(self.full_table_name, self.definition, context) if uses_external: sql = sql.format(external_table=self.external_table...
python
def declare(self, context=None): """ Use self.definition to declare the table in the schema. """ try: sql, uses_external = declare(self.full_table_name, self.definition, context) if uses_external: sql = sql.format(external_table=self.external_table...
[ "def", "declare", "(", "self", ",", "context", "=", "None", ")", ":", "try", ":", "sql", ",", "uses_external", "=", "declare", "(", "self", ".", "full_table_name", ",", "self", ".", "definition", ",", "context", ")", "if", "uses_external", ":", "sql", ...
Use self.definition to declare the table in the schema.
[ "Use", "self", ".", "definition", "to", "declare", "the", "table", "in", "the", "schema", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L58-L74
datajoint/datajoint-python
datajoint/table.py
Table.parents
def parents(self, primary=None): """ :param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-primary attribute are considered. :r...
python
def parents(self, primary=None): """ :param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-primary attribute are considered. :r...
[ "def", "parents", "(", "self", ",", "primary", "=", "None", ")", ":", "return", "self", ".", "connection", ".", "dependencies", ".", "parents", "(", "self", ".", "full_table_name", ",", "primary", ")" ]
:param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-primary attribute are considered. :return: dict of tables referenced with self's foreign ...
[ ":", "param", "primary", ":", "if", "None", "then", "all", "parents", "are", "returned", ".", "If", "True", "then", "only", "foreign", "keys", "composed", "of", "primary", "key", "attributes", "are", "considered", ".", "If", "False", "the", "only", "foreig...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L89-L96
datajoint/datajoint-python
datajoint/table.py
Table.children
def children(self, primary=None): """ :param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-primary attribute are considered. :...
python
def children(self, primary=None): """ :param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-primary attribute are considered. :...
[ "def", "children", "(", "self", ",", "primary", "=", "None", ")", ":", "return", "self", ".", "connection", ".", "dependencies", ".", "children", "(", "self", ".", "full_table_name", ",", "primary", ")" ]
:param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-primary attribute are considered. :return: dict of tables with foreign keys referencing s...
[ ":", "param", "primary", ":", "if", "None", "then", "all", "parents", "are", "returned", ".", "If", "True", "then", "only", "foreign", "keys", "composed", "of", "primary", "key", "attributes", "are", "considered", ".", "If", "False", "the", "only", "foreig...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L98-L105
datajoint/datajoint-python
datajoint/table.py
Table.is_declared
def is_declared(self): """ :return: True is the table is declared in the schema. """ return self.connection.query( 'SHOW TABLES in `{database}` LIKE "{table_name}"'.format( database=self.database, table_name=self.table_name)).rowcount > 0
python
def is_declared(self): """ :return: True is the table is declared in the schema. """ return self.connection.query( 'SHOW TABLES in `{database}` LIKE "{table_name}"'.format( database=self.database, table_name=self.table_name)).rowcount > 0
[ "def", "is_declared", "(", "self", ")", ":", "return", "self", ".", "connection", ".", "query", "(", "'SHOW TABLES in `{database}` LIKE \"{table_name}\"'", ".", "format", "(", "database", "=", "self", ".", "database", ",", "table_name", "=", "self", ".", "table_...
:return: True is the table is declared in the schema.
[ ":", "return", ":", "True", "is", "the", "table", "is", "declared", "in", "the", "schema", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L114-L120
datajoint/datajoint-python
datajoint/table.py
Table.insert
def insert(self, rows, replace=False, skip_duplicates=False, ignore_extra_fields=False, allow_direct_insert=None): """ Insert a collection of rows. :param rows: An iterable where an element is a numpy record, a dict-like object, a pandas.DataFrame, a sequence, or a query expression ...
python
def insert(self, rows, replace=False, skip_duplicates=False, ignore_extra_fields=False, allow_direct_insert=None): """ Insert a collection of rows. :param rows: An iterable where an element is a numpy record, a dict-like object, a pandas.DataFrame, a sequence, or a query expression ...
[ "def", "insert", "(", "self", ",", "rows", ",", "replace", "=", "False", ",", "skip_duplicates", "=", "False", ",", "ignore_extra_fields", "=", "False", ",", "allow_direct_insert", "=", "None", ")", ":", "if", "isinstance", "(", "rows", ",", "pandas", ".",...
Insert a collection of rows. :param rows: An iterable where an element is a numpy record, a dict-like object, a pandas.DataFrame, a sequence, or a query expression with the same heading as table self. :param replace: If True, replaces the existing tuple. :param skip_duplicates: If T...
[ "Insert", "a", "collection", "of", "rows", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L150-L311
datajoint/datajoint-python
datajoint/table.py
Table.delete_quick
def delete_quick(self, get_count=False): """ Deletes the table without cascading and without user prompt. If this table has populated dependent tables, this will fail. """ query = 'DELETE FROM ' + self.full_table_name + self.where_clause self.connection.query(query) ...
python
def delete_quick(self, get_count=False): """ Deletes the table without cascading and without user prompt. If this table has populated dependent tables, this will fail. """ query = 'DELETE FROM ' + self.full_table_name + self.where_clause self.connection.query(query) ...
[ "def", "delete_quick", "(", "self", ",", "get_count", "=", "False", ")", ":", "query", "=", "'DELETE FROM '", "+", "self", ".", "full_table_name", "+", "self", ".", "where_clause", "self", ".", "connection", ".", "query", "(", "query", ")", "count", "=", ...
Deletes the table without cascading and without user prompt. If this table has populated dependent tables, this will fail.
[ "Deletes", "the", "table", "without", "cascading", "and", "without", "user", "prompt", ".", "If", "this", "table", "has", "populated", "dependent", "tables", "this", "will", "fail", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L313-L322
datajoint/datajoint-python
datajoint/table.py
Table.delete
def delete(self, verbose=True): """ Deletes the contents of the table and its dependent tables, recursively. User is prompted for confirmation if config['safemode'] is set to True. """ conn = self.connection already_in_transaction = conn.in_transaction safe = conf...
python
def delete(self, verbose=True): """ Deletes the contents of the table and its dependent tables, recursively. User is prompted for confirmation if config['safemode'] is set to True. """ conn = self.connection already_in_transaction = conn.in_transaction safe = conf...
[ "def", "delete", "(", "self", ",", "verbose", "=", "True", ")", ":", "conn", "=", "self", ".", "connection", "already_in_transaction", "=", "conn", ".", "in_transaction", "safe", "=", "config", "[", "'safemode'", "]", "if", "already_in_transaction", "and", "...
Deletes the contents of the table and its dependent tables, recursively. User is prompted for confirmation if config['safemode'] is set to True.
[ "Deletes", "the", "contents", "of", "the", "table", "and", "its", "dependent", "tables", "recursively", ".", "User", "is", "prompted", "for", "confirmation", "if", "config", "[", "safemode", "]", "is", "set", "to", "True", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L324-L406
datajoint/datajoint-python
datajoint/table.py
Table.drop_quick
def drop_quick(self): """ Drops the table associated with this relation without cascading and without user prompt. If the table has any dependent table(s), this call will fail with an error. """ if self.is_declared: query = 'DROP TABLE %s' % self.full_table_name ...
python
def drop_quick(self): """ Drops the table associated with this relation without cascading and without user prompt. If the table has any dependent table(s), this call will fail with an error. """ if self.is_declared: query = 'DROP TABLE %s' % self.full_table_name ...
[ "def", "drop_quick", "(", "self", ")", ":", "if", "self", ".", "is_declared", ":", "query", "=", "'DROP TABLE %s'", "%", "self", ".", "full_table_name", "self", ".", "connection", ".", "query", "(", "query", ")", "logger", ".", "info", "(", "\"Dropped tabl...
Drops the table associated with this relation without cascading and without user prompt. If the table has any dependent table(s), this call will fail with an error.
[ "Drops", "the", "table", "associated", "with", "this", "relation", "without", "cascading", "and", "without", "user", "prompt", ".", "If", "the", "table", "has", "any", "dependent", "table", "(", "s", ")", "this", "call", "will", "fail", "with", "an", "erro...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L408-L419
datajoint/datajoint-python
datajoint/table.py
Table.drop
def drop(self): """ Drop the table and all tables that reference it, recursively. User is prompted for confirmation if config['safemode'] is set to True. """ if self.restriction: raise DataJointError('A relation with an applied restriction condition cannot be dropped....
python
def drop(self): """ Drop the table and all tables that reference it, recursively. User is prompted for confirmation if config['safemode'] is set to True. """ if self.restriction: raise DataJointError('A relation with an applied restriction condition cannot be dropped....
[ "def", "drop", "(", "self", ")", ":", "if", "self", ".", "restriction", ":", "raise", "DataJointError", "(", "'A relation with an applied restriction condition cannot be dropped.'", "' Call drop() on the unrestricted Table.'", ")", "self", ".", "connection", ".", "dependenc...
Drop the table and all tables that reference it, recursively. User is prompted for confirmation if config['safemode'] is set to True.
[ "Drop", "the", "table", "and", "all", "tables", "that", "reference", "it", "recursively", ".", "User", "is", "prompted", "for", "confirmation", "if", "config", "[", "safemode", "]", "is", "set", "to", "True", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L421-L440
datajoint/datajoint-python
datajoint/table.py
Table.size_on_disk
def size_on_disk(self): """ :return: size of data and indices in bytes on the storage device """ ret = self.connection.query( 'SHOW TABLE STATUS FROM `{database}` WHERE NAME="{table}"'.format( database=self.database, table=self.table_name), as_dict=True).fetch...
python
def size_on_disk(self): """ :return: size of data and indices in bytes on the storage device """ ret = self.connection.query( 'SHOW TABLE STATUS FROM `{database}` WHERE NAME="{table}"'.format( database=self.database, table=self.table_name), as_dict=True).fetch...
[ "def", "size_on_disk", "(", "self", ")", ":", "ret", "=", "self", ".", "connection", ".", "query", "(", "'SHOW TABLE STATUS FROM `{database}` WHERE NAME=\"{table}\"'", ".", "format", "(", "database", "=", "self", ".", "database", ",", "table", "=", "self", ".", ...
:return: size of data and indices in bytes on the storage device
[ ":", "return", ":", "size", "of", "data", "and", "indices", "in", "bytes", "on", "the", "storage", "device" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L443-L450
datajoint/datajoint-python
datajoint/table.py
Table.describe
def describe(self, context=None, printout=True): """ :return: the definition string for the relation using DataJoint DDL. This does not yet work for aliased foreign keys. """ if context is None: frame = inspect.currentframe().f_back context = dict(fra...
python
def describe(self, context=None, printout=True): """ :return: the definition string for the relation using DataJoint DDL. This does not yet work for aliased foreign keys. """ if context is None: frame = inspect.currentframe().f_back context = dict(fra...
[ "def", "describe", "(", "self", ",", "context", "=", "None", ",", "printout", "=", "True", ")", ":", "if", "context", "is", "None", ":", "frame", "=", "inspect", ".", "currentframe", "(", ")", ".", "f_back", "context", "=", "dict", "(", "frame", ".",...
:return: the definition string for the relation using DataJoint DDL. This does not yet work for aliased foreign keys.
[ ":", "return", ":", "the", "definition", "string", "for", "the", "relation", "using", "DataJoint", "DDL", ".", "This", "does", "not", "yet", "work", "for", "aliased", "foreign", "keys", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L456-L523
datajoint/datajoint-python
datajoint/table.py
Table._update
def _update(self, attrname, value=None): """ Updates a field in an existing tuple. This is not a datajoyous operation and should not be used routinely. Relational database maintain referential integrity on the level of a tuple. Therefore, the UPDATE operator can violate refer...
python
def _update(self, attrname, value=None): """ Updates a field in an existing tuple. This is not a datajoyous operation and should not be used routinely. Relational database maintain referential integrity on the level of a tuple. Therefore, the UPDATE operator can violate refer...
[ "def", "_update", "(", "self", ",", "attrname", ",", "value", "=", "None", ")", ":", "if", "len", "(", "self", ")", "!=", "1", ":", "raise", "DataJointError", "(", "'Update is only allowed on one tuple at a time'", ")", "if", "attrname", "not", "in", "self",...
Updates a field in an existing tuple. This is not a datajoyous operation and should not be used routinely. Relational database maintain referential integrity on the level of a tuple. Therefore, the UPDATE operator can violate referential integrity. The datajoyous way to update information is ...
[ "Updates", "a", "field", "in", "an", "existing", "tuple", ".", "This", "is", "not", "a", "datajoyous", "operation", "and", "should", "not", "be", "used", "routinely", ".", "Relational", "database", "maintain", "referential", "integrity", "on", "the", "level", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/table.py#L525-L568
datajoint/datajoint-python
datajoint/expression.py
assert_join_compatibility
def assert_join_compatibility(rel1, rel2): """ Determine if expressions rel1 and rel2 are join-compatible. To be join-compatible, the matching attributes in the two expressions must be in the primary key of one or the other expression. Raises an exception if not compatible. :param rel1: A QueryExpr...
python
def assert_join_compatibility(rel1, rel2): """ Determine if expressions rel1 and rel2 are join-compatible. To be join-compatible, the matching attributes in the two expressions must be in the primary key of one or the other expression. Raises an exception if not compatible. :param rel1: A QueryExpr...
[ "def", "assert_join_compatibility", "(", "rel1", ",", "rel2", ")", ":", "for", "rel", "in", "(", "rel1", ",", "rel2", ")", ":", "if", "not", "isinstance", "(", "rel", ",", "(", "U", ",", "QueryExpression", ")", ")", ":", "raise", "DataJointError", "(",...
Determine if expressions rel1 and rel2 are join-compatible. To be join-compatible, the matching attributes in the two expressions must be in the primary key of one or the other expression. Raises an exception if not compatible. :param rel1: A QueryExpression object :param rel2: A QueryExpression object
[ "Determine", "if", "expressions", "rel1", "and", "rel2", "are", "join", "-", "compatible", ".", "To", "be", "join", "-", "compatible", "the", "matching", "attributes", "in", "the", "two", "expressions", "must", "be", "in", "the", "primary", "key", "of", "o...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L17-L33
datajoint/datajoint-python
datajoint/expression.py
QueryExpression._make_condition
def _make_condition(self, arg): """ Translate the input arg into the equivalent SQL condition (a string) :param arg: any valid restriction object. :return: an SQL condition string or a boolean value. """ def prep_value(v): return str(v) if isinstance(v, (datet...
python
def _make_condition(self, arg): """ Translate the input arg into the equivalent SQL condition (a string) :param arg: any valid restriction object. :return: an SQL condition string or a boolean value. """ def prep_value(v): return str(v) if isinstance(v, (datet...
[ "def", "_make_condition", "(", "self", ",", "arg", ")", ":", "def", "prep_value", "(", "v", ")", ":", "return", "str", "(", "v", ")", "if", "isinstance", "(", "v", ",", "(", "datetime", ".", "date", ",", "datetime", ".", "datetime", ",", "datetime", ...
Translate the input arg into the equivalent SQL condition (a string) :param arg: any valid restriction object. :return: an SQL condition string or a boolean value.
[ "Translate", "the", "input", "arg", "into", "the", "equivalent", "SQL", "condition", "(", "a", "string", ")", ":", "param", "arg", ":", "any", "valid", "restriction", "object", ".", ":", "return", ":", "an", "SQL", "condition", "string", "or", "a", "bool...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L117-L193
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.where_clause
def where_clause(self): """ convert self.restriction to the SQL WHERE clause """ cond = self._make_condition(self.restriction) return '' if cond is True else ' WHERE %s' % cond
python
def where_clause(self): """ convert self.restriction to the SQL WHERE clause """ cond = self._make_condition(self.restriction) return '' if cond is True else ' WHERE %s' % cond
[ "def", "where_clause", "(", "self", ")", ":", "cond", "=", "self", ".", "_make_condition", "(", "self", ".", "restriction", ")", "return", "''", "if", "cond", "is", "True", "else", "' WHERE %s'", "%", "cond" ]
convert self.restriction to the SQL WHERE clause
[ "convert", "self", ".", "restriction", "to", "the", "SQL", "WHERE", "clause" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L196-L201
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.get_select_fields
def get_select_fields(self, select_fields=None): """ :return: string specifying the attributes to return """ return self.heading.as_sql if select_fields is None else self.heading.project(select_fields).as_sql
python
def get_select_fields(self, select_fields=None): """ :return: string specifying the attributes to return """ return self.heading.as_sql if select_fields is None else self.heading.project(select_fields).as_sql
[ "def", "get_select_fields", "(", "self", ",", "select_fields", "=", "None", ")", ":", "return", "self", ".", "heading", ".", "as_sql", "if", "select_fields", "is", "None", "else", "self", ".", "heading", ".", "project", "(", "select_fields", ")", ".", "as_...
:return: string specifying the attributes to return
[ ":", "return", ":", "string", "specifying", "the", "attributes", "to", "return" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L203-L207
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.aggr
def aggr(self, group, *attributes, keep_all_rows=False, **named_attributes): """ Aggregation/projection operator :param group: an entity set whose entities will be grouped per entity of `self` :param attributes: attributes of self to include in the result :param keep_all_rows: T...
python
def aggr(self, group, *attributes, keep_all_rows=False, **named_attributes): """ Aggregation/projection operator :param group: an entity set whose entities will be grouped per entity of `self` :param attributes: attributes of self to include in the result :param keep_all_rows: T...
[ "def", "aggr", "(", "self", ",", "group", ",", "*", "attributes", ",", "keep_all_rows", "=", "False", ",", "*", "*", "named_attributes", ")", ":", "return", "GroupBy", ".", "create", "(", "self", ",", "group", ",", "keep_all_rows", "=", "keep_all_rows", ...
Aggregation/projection operator :param group: an entity set whose entities will be grouped per entity of `self` :param attributes: attributes of self to include in the result :param keep_all_rows: True = preserve the number of elements in the result (equivalent of LEFT JOIN in SQL) :par...
[ "Aggregation", "/", "projection", "operator", ":", "param", "group", ":", "an", "entity", "set", "whose", "entities", "will", "be", "grouped", "per", "entity", "of", "self", ":", "param", "attributes", ":", "attributes", "of", "self", "to", "include", "in", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L238-L249
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.restrict
def restrict(self, restriction): """ In-place restriction. Restricts the result to a specified subset of the input. rel.restrict(restriction) is equivalent to rel = rel & restriction or rel &= restriction rel.restrict(Not(restriction)) is equivalent to rel = rel - restriction or ...
python
def restrict(self, restriction): """ In-place restriction. Restricts the result to a specified subset of the input. rel.restrict(restriction) is equivalent to rel = rel & restriction or rel &= restriction rel.restrict(Not(restriction)) is equivalent to rel = rel - restriction or ...
[ "def", "restrict", "(", "self", ",", "restriction", ")", ":", "assert", "is_true", "(", "restriction", ")", "or", "not", "self", ".", "heading", ".", "expressions", "or", "isinstance", "(", "self", ",", "GroupBy", ")", ",", "\"Cannot restrict a projection with...
In-place restriction. Restricts the result to a specified subset of the input. rel.restrict(restriction) is equivalent to rel = rel & restriction or rel &= restriction rel.restrict(Not(restriction)) is equivalent to rel = rel - restriction or rel -= restriction The primary key of the re...
[ "In", "-", "place", "restriction", ".", "Restricts", "the", "result", "to", "a", "specified", "subset", "of", "the", "input", ".", "rel", ".", "restrict", "(", "restriction", ")", "is", "equivalent", "to", "rel", "=", "rel", "&", "restriction", "or", "re...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L291-L339
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.head
def head(self, limit=25, **fetch_kwargs): """ shortcut to fetch the first few entries from query expression. Equivalent to fetch(order_by="KEY", limit=25) :param limit: number of entries :param fetch_kwargs: kwargs for fetch :return: query result """ retu...
python
def head(self, limit=25, **fetch_kwargs): """ shortcut to fetch the first few entries from query expression. Equivalent to fetch(order_by="KEY", limit=25) :param limit: number of entries :param fetch_kwargs: kwargs for fetch :return: query result """ retu...
[ "def", "head", "(", "self", ",", "limit", "=", "25", ",", "*", "*", "fetch_kwargs", ")", ":", "return", "self", ".", "fetch", "(", "order_by", "=", "\"KEY\"", ",", "limit", "=", "limit", ",", "*", "*", "fetch_kwargs", ")" ]
shortcut to fetch the first few entries from query expression. Equivalent to fetch(order_by="KEY", limit=25) :param limit: number of entries :param fetch_kwargs: kwargs for fetch :return: query result
[ "shortcut", "to", "fetch", "the", "first", "few", "entries", "from", "query", "expression", ".", "Equivalent", "to", "fetch", "(", "order_by", "=", "KEY", "limit", "=", "25", ")", ":", "param", "limit", ":", "number", "of", "entries", ":", "param", "fetc...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L349-L357
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.tail
def tail(self, limit=25, **fetch_kwargs): """ shortcut to fetch the last few entries from query expression. Equivalent to fetch(order_by="KEY DESC", limit=25)[::-1] :param limit: number of entries :param fetch_kwargs: kwargs for fetch :return: query result """ ...
python
def tail(self, limit=25, **fetch_kwargs): """ shortcut to fetch the last few entries from query expression. Equivalent to fetch(order_by="KEY DESC", limit=25)[::-1] :param limit: number of entries :param fetch_kwargs: kwargs for fetch :return: query result """ ...
[ "def", "tail", "(", "self", ",", "limit", "=", "25", ",", "*", "*", "fetch_kwargs", ")", ":", "return", "self", ".", "fetch", "(", "order_by", "=", "\"KEY DESC\"", ",", "limit", "=", "limit", ",", "*", "*", "fetch_kwargs", ")", "[", ":", ":", "-", ...
shortcut to fetch the last few entries from query expression. Equivalent to fetch(order_by="KEY DESC", limit=25)[::-1] :param limit: number of entries :param fetch_kwargs: kwargs for fetch :return: query result
[ "shortcut", "to", "fetch", "the", "last", "few", "entries", "from", "query", "expression", ".", "Equivalent", "to", "fetch", "(", "order_by", "=", "KEY", "DESC", "limit", "=", "25", ")", "[", "::", "-", "1", "]", ":", "param", "limit", ":", "number", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L359-L367
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.attributes_in_restriction
def attributes_in_restriction(self): """ :return: list of attributes that are probably used in the restriction. The function errs on the side of false positives. For example, if the restriction is "val='id'", then the attribute 'id' would be flagged. This is used inte...
python
def attributes_in_restriction(self): """ :return: list of attributes that are probably used in the restriction. The function errs on the side of false positives. For example, if the restriction is "val='id'", then the attribute 'id' would be flagged. This is used inte...
[ "def", "attributes_in_restriction", "(", "self", ")", ":", "return", "set", "(", "name", "for", "name", "in", "self", ".", "heading", ".", "names", "if", "re", ".", "search", "(", "r'\\b'", "+", "name", "+", "r'\\b'", ",", "self", ".", "where_clause", ...
:return: list of attributes that are probably used in the restriction. The function errs on the side of false positives. For example, if the restriction is "val='id'", then the attribute 'id' would be flagged. This is used internally for optimizing SQL statements.
[ ":", "return", ":", "list", "of", "attributes", "that", "are", "probably", "used", "in", "the", "restriction", ".", "The", "function", "errs", "on", "the", "side", "of", "false", "positives", ".", "For", "example", "if", "the", "restriction", "is", "val", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L369-L377
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.preview
def preview(self, limit=None, width=None): """ returns a preview of the contents of the query. """ heading = self.heading rel = self.proj(*heading.non_blobs) if limit is None: limit = config['display.limit'] if width is None: width = config...
python
def preview(self, limit=None, width=None): """ returns a preview of the contents of the query. """ heading = self.heading rel = self.proj(*heading.non_blobs) if limit is None: limit = config['display.limit'] if width is None: width = config...
[ "def", "preview", "(", "self", ",", "limit", "=", "None", ",", "width", "=", "None", ")", ":", "heading", "=", "self", ".", "heading", "rel", "=", "self", ".", "proj", "(", "*", "heading", ".", "non_blobs", ")", "if", "limit", "is", "None", ":", ...
returns a preview of the contents of the query.
[ "returns", "a", "preview", "of", "the", "contents", "of", "the", "query", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L382-L405
datajoint/datajoint-python
datajoint/expression.py
QueryExpression.cursor
def cursor(self, offset=0, limit=None, order_by=None, as_dict=False): """ See expression.fetch() for input description. :return: query cursor """ if offset and limit is None: raise DataJointError('limit is required when offset is set') sql = self.make_sql() ...
python
def cursor(self, offset=0, limit=None, order_by=None, as_dict=False): """ See expression.fetch() for input description. :return: query cursor """ if offset and limit is None: raise DataJointError('limit is required when offset is set') sql = self.make_sql() ...
[ "def", "cursor", "(", "self", ",", "offset", "=", "0", ",", "limit", "=", "None", ",", "order_by", "=", "None", ",", "as_dict", "=", "False", ")", ":", "if", "offset", "and", "limit", "is", "None", ":", "raise", "DataJointError", "(", "'limit is requir...
See expression.fetch() for input description. :return: query cursor
[ "See", "expression", ".", "fetch", "()", "for", "input", "description", ".", ":", "return", ":", "query", "cursor" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L547-L560
datajoint/datajoint-python
datajoint/expression.py
Join.make_argument_subquery
def make_argument_subquery(arg): """ Decide when a Join argument needs to be wrapped in a subquery """ return Subquery.create(arg) if isinstance(arg, (GroupBy, Projection)) or arg.restriction else arg
python
def make_argument_subquery(arg): """ Decide when a Join argument needs to be wrapped in a subquery """ return Subquery.create(arg) if isinstance(arg, (GroupBy, Projection)) or arg.restriction else arg
[ "def", "make_argument_subquery", "(", "arg", ")", ":", "return", "Subquery", ".", "create", "(", "arg", ")", "if", "isinstance", "(", "arg", ",", "(", "GroupBy", ",", "Projection", ")", ")", "or", "arg", ".", "restriction", "else", "arg" ]
Decide when a Join argument needs to be wrapped in a subquery
[ "Decide", "when", "a", "Join", "argument", "needs", "to", "be", "wrapped", "in", "a", "subquery" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L606-L610
datajoint/datajoint-python
datajoint/expression.py
Projection.create
def create(cls, arg, attributes=None, named_attributes=None, include_primary_key=True): """ :param arg: The QueryExression to be projected :param attributes: attributes to select :param named_attributes: new attributes to create by renaming or computing :param include_primary_k...
python
def create(cls, arg, attributes=None, named_attributes=None, include_primary_key=True): """ :param arg: The QueryExression to be projected :param attributes: attributes to select :param named_attributes: new attributes to create by renaming or computing :param include_primary_k...
[ "def", "create", "(", "cls", ",", "arg", ",", "attributes", "=", "None", ",", "named_attributes", "=", "None", ",", "include_primary_key", "=", "True", ")", ":", "obj", "=", "cls", "(", ")", "obj", ".", "_connection", "=", "arg", ".", "connection", "na...
:param arg: The QueryExression to be projected :param attributes: attributes to select :param named_attributes: new attributes to create by renaming or computing :param include_primary_key: True if the primary key must be included even if it's not in attributes. :return: the resulting...
[ ":", "param", "arg", ":", "The", "QueryExression", "to", "be", "projected", ":", "param", "attributes", ":", "attributes", "to", "select", ":", "param", "named_attributes", ":", "new", "attributes", "to", "create", "by", "renaming", "or", "computing", ":", "...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L686-L714
datajoint/datajoint-python
datajoint/expression.py
Projection._need_subquery
def _need_subquery(arg, attributes, named_attributes): """ Decide whether the projection argument needs to be wrapped in a subquery """ if arg.heading.expressions or arg.distinct: # argument has any renamed (computed) attributes return True restricting_attributes = a...
python
def _need_subquery(arg, attributes, named_attributes): """ Decide whether the projection argument needs to be wrapped in a subquery """ if arg.heading.expressions or arg.distinct: # argument has any renamed (computed) attributes return True restricting_attributes = a...
[ "def", "_need_subquery", "(", "arg", ",", "attributes", ",", "named_attributes", ")", ":", "if", "arg", ".", "heading", ".", "expressions", "or", "arg", ".", "distinct", ":", "# argument has any renamed (computed) attributes", "return", "True", "restricting_attributes...
Decide whether the projection argument needs to be wrapped in a subquery
[ "Decide", "whether", "the", "projection", "argument", "needs", "to", "be", "wrapped", "in", "a", "subquery" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L717-L725
datajoint/datajoint-python
datajoint/expression.py
Subquery.create
def create(cls, arg): """ construct a subquery from arg """ obj = cls() obj._connection = arg.connection obj._heading = arg.heading.make_subquery_heading() obj._arg = arg return obj
python
def create(cls, arg): """ construct a subquery from arg """ obj = cls() obj._connection = arg.connection obj._heading = arg.heading.make_subquery_heading() obj._arg = arg return obj
[ "def", "create", "(", "cls", ",", "arg", ")", ":", "obj", "=", "cls", "(", ")", "obj", ".", "_connection", "=", "arg", ".", "connection", "obj", ".", "_heading", "=", "arg", ".", "heading", ".", "make_subquery_heading", "(", ")", "obj", ".", "_arg", ...
construct a subquery from arg
[ "construct", "a", "subquery", "from", "arg" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L800-L808
datajoint/datajoint-python
datajoint/expression.py
U.aggr
def aggr(self, group, **named_attributes): """ Aggregation of the type U('attr1','attr2').aggr(group, computation="QueryExpression") has the primary key ('attr1','attr2') and performs aggregation computations for all matching elements of `group`. :param group: The query expression to be...
python
def aggr(self, group, **named_attributes): """ Aggregation of the type U('attr1','attr2').aggr(group, computation="QueryExpression") has the primary key ('attr1','attr2') and performs aggregation computations for all matching elements of `group`. :param group: The query expression to be...
[ "def", "aggr", "(", "self", ",", "group", ",", "*", "*", "named_attributes", ")", ":", "return", "(", "GroupBy", ".", "create", "(", "self", ",", "group", "=", "group", ",", "keep_all_rows", "=", "False", ",", "attributes", "=", "(", ")", ",", "named...
Aggregation of the type U('attr1','attr2').aggr(group, computation="QueryExpression") has the primary key ('attr1','attr2') and performs aggregation computations for all matching elements of `group`. :param group: The query expression to be aggregated. :param named_attributes: computations of t...
[ "Aggregation", "of", "the", "type", "U", "(", "attr1", "attr2", ")", ".", "aggr", "(", "group", "computation", "=", "QueryExpression", ")", "has", "the", "primary", "key", "(", "attr1", "attr2", ")", "and", "performs", "aggregation", "computations", "for", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/expression.py#L899-L910
datajoint/datajoint-python
datajoint/utils.py
user_choice
def user_choice(prompt, choices=("yes", "no"), default=None): """ Prompts the user for confirmation. The default value, if any, is capitalized. :param prompt: Information to display to the user. :param choices: an iterable of possible choices. :param default: default choice :return: the user's...
python
def user_choice(prompt, choices=("yes", "no"), default=None): """ Prompts the user for confirmation. The default value, if any, is capitalized. :param prompt: Information to display to the user. :param choices: an iterable of possible choices. :param default: default choice :return: the user's...
[ "def", "user_choice", "(", "prompt", ",", "choices", "=", "(", "\"yes\"", ",", "\"no\"", ")", ",", "default", "=", "None", ")", ":", "assert", "default", "is", "None", "or", "default", "in", "choices", "choice_list", "=", "', '", ".", "join", "(", "(",...
Prompts the user for confirmation. The default value, if any, is capitalized. :param prompt: Information to display to the user. :param choices: an iterable of possible choices. :param default: default choice :return: the user's choice
[ "Prompts", "the", "user", "for", "confirmation", ".", "The", "default", "value", "if", "any", "is", "capitalized", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/utils.py#L16-L31
datajoint/datajoint-python
datajoint/utils.py
to_camel_case
def to_camel_case(s): """ Convert names with under score (_) separation into camel case names. :param s: string in under_score notation :returns: string in CamelCase notation Example: >>> to_camel_case("table_name") # yields "TableName" """ def to_upper(match): return match.gr...
python
def to_camel_case(s): """ Convert names with under score (_) separation into camel case names. :param s: string in under_score notation :returns: string in CamelCase notation Example: >>> to_camel_case("table_name") # yields "TableName" """ def to_upper(match): return match.gr...
[ "def", "to_camel_case", "(", "s", ")", ":", "def", "to_upper", "(", "match", ")", ":", "return", "match", ".", "group", "(", "0", ")", "[", "-", "1", "]", ".", "upper", "(", ")", "return", "re", ".", "sub", "(", "'(^|[_\\W])+[a-zA-Z]'", ",", "to_up...
Convert names with under score (_) separation into camel case names. :param s: string in under_score notation :returns: string in CamelCase notation Example: >>> to_camel_case("table_name") # yields "TableName"
[ "Convert", "names", "with", "under", "score", "(", "_", ")", "separation", "into", "camel", "case", "names", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/utils.py#L34-L48
datajoint/datajoint-python
datajoint/utils.py
from_camel_case
def from_camel_case(s): """ Convert names in camel case into underscore (_) separated names :param s: string in CamelCase notation :returns: string in under_score notation Example: >>> from_camel_case("TableName") # yields "table_name" """ def convert(match): return ('_' if ...
python
def from_camel_case(s): """ Convert names in camel case into underscore (_) separated names :param s: string in CamelCase notation :returns: string in under_score notation Example: >>> from_camel_case("TableName") # yields "table_name" """ def convert(match): return ('_' if ...
[ "def", "from_camel_case", "(", "s", ")", ":", "def", "convert", "(", "match", ")", ":", "return", "(", "'_'", "if", "match", ".", "groups", "(", ")", "[", "0", "]", "else", "''", ")", "+", "match", ".", "group", "(", "0", ")", ".", "lower", "("...
Convert names in camel case into underscore (_) separated names :param s: string in CamelCase notation :returns: string in under_score notation Example: >>> from_camel_case("TableName") # yields "table_name"
[ "Convert", "names", "in", "camel", "case", "into", "underscore", "(", "_", ")", "separated", "names" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/utils.py#L51-L70
datajoint/datajoint-python
datajoint/utils.py
safe_write
def safe_write(filename, blob): """ A two-step write. :param filename: full path :param blob: binary data :return: None """ temp_file = filename + '.saving' with open(temp_file, 'bw') as f: f.write(blob) os.rename(temp_file, filename)
python
def safe_write(filename, blob): """ A two-step write. :param filename: full path :param blob: binary data :return: None """ temp_file = filename + '.saving' with open(temp_file, 'bw') as f: f.write(blob) os.rename(temp_file, filename)
[ "def", "safe_write", "(", "filename", ",", "blob", ")", ":", "temp_file", "=", "filename", "+", "'.saving'", "with", "open", "(", "temp_file", ",", "'bw'", ")", "as", "f", ":", "f", ".", "write", "(", "blob", ")", "os", ".", "rename", "(", "temp_file...
A two-step write. :param filename: full path :param blob: binary data :return: None
[ "A", "two", "-", "step", "write", ".", ":", "param", "filename", ":", "full", "path", ":", "param", "blob", ":", "binary", "data", ":", "return", ":", "None" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/utils.py#L73-L83
datajoint/datajoint-python
datajoint/fetch.py
to_dicts
def to_dicts(recarray): """convert record array to a dictionaries""" for rec in recarray: yield dict(zip(recarray.dtype.names, rec.tolist()))
python
def to_dicts(recarray): """convert record array to a dictionaries""" for rec in recarray: yield dict(zip(recarray.dtype.names, rec.tolist()))
[ "def", "to_dicts", "(", "recarray", ")", ":", "for", "rec", "in", "recarray", ":", "yield", "dict", "(", "zip", "(", "recarray", ".", "dtype", ".", "names", ",", "rec", ".", "tolist", "(", ")", ")", ")" ]
convert record array to a dictionaries
[ "convert", "record", "array", "to", "a", "dictionaries" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/fetch.py#L24-L27
datajoint/datajoint-python
datajoint/fetch.py
Fetch.keys
def keys(self, **kwargs): """ DEPRECATED Iterator that returns primary keys as a sequence of dicts. """ warnings.warn('Use of `rel.fetch.keys()` notation is deprecated. ' 'Please use `rel.fetch("KEY")` or `rel.fetch(dj.key)` for equivalent result', stackleve...
python
def keys(self, **kwargs): """ DEPRECATED Iterator that returns primary keys as a sequence of dicts. """ warnings.warn('Use of `rel.fetch.keys()` notation is deprecated. ' 'Please use `rel.fetch("KEY")` or `rel.fetch(dj.key)` for equivalent result', stackleve...
[ "def", "keys", "(", "self", ",", "*", "*", "kwargs", ")", ":", "warnings", ".", "warn", "(", "'Use of `rel.fetch.keys()` notation is deprecated. '", "'Please use `rel.fetch(\"KEY\")` or `rel.fetch(dj.key)` for equivalent result'", ",", "stacklevel", "=", "2", ")", "yield", ...
DEPRECATED Iterator that returns primary keys as a sequence of dicts.
[ "DEPRECATED", "Iterator", "that", "returns", "primary", "keys", "as", "a", "sequence", "of", "dicts", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/fetch.py#L131-L138
datajoint/datajoint-python
datajoint/hash.py
key_hash
def key_hash(key): """ 32-byte hash used for lookup of primary keys of jobs """ hashed = hashlib.md5() for k, v in sorted(key.items()): hashed.update(str(v).encode()) return hashed.hexdigest()
python
def key_hash(key): """ 32-byte hash used for lookup of primary keys of jobs """ hashed = hashlib.md5() for k, v in sorted(key.items()): hashed.update(str(v).encode()) return hashed.hexdigest()
[ "def", "key_hash", "(", "key", ")", ":", "hashed", "=", "hashlib", ".", "md5", "(", ")", "for", "k", ",", "v", "in", "sorted", "(", "key", ".", "items", "(", ")", ")", ":", "hashed", ".", "update", "(", "str", "(", "v", ")", ".", "encode", "(...
32-byte hash used for lookup of primary keys of jobs
[ "32", "-", "byte", "hash", "used", "for", "lookup", "of", "primary", "keys", "of", "jobs" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/hash.py#L5-L12
datajoint/datajoint-python
datajoint/hash.py
long_hash
def long_hash(*buffers): """ :param buffer: a binary buffer (e.g. serialized blob) :return: 43-character base64 ASCII rendition SHA-256 """ hashed = hashlib.sha256() for buffer in buffers: hashed.update(buffer) return to_ascii(hashed.digest())[0:43]
python
def long_hash(*buffers): """ :param buffer: a binary buffer (e.g. serialized blob) :return: 43-character base64 ASCII rendition SHA-256 """ hashed = hashlib.sha256() for buffer in buffers: hashed.update(buffer) return to_ascii(hashed.digest())[0:43]
[ "def", "long_hash", "(", "*", "buffers", ")", ":", "hashed", "=", "hashlib", ".", "sha256", "(", ")", "for", "buffer", "in", "buffers", ":", "hashed", ".", "update", "(", "buffer", ")", "return", "to_ascii", "(", "hashed", ".", "digest", "(", ")", ")...
:param buffer: a binary buffer (e.g. serialized blob) :return: 43-character base64 ASCII rendition SHA-256
[ ":", "param", "buffer", ":", "a", "binary", "buffer", "(", "e", ".", "g", ".", "serialized", "blob", ")", ":", "return", ":", "43", "-", "character", "base64", "ASCII", "rendition", "SHA", "-", "256" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/hash.py#L23-L31
datajoint/datajoint-python
datajoint/hash.py
short_hash
def short_hash(*buffers): """ :param buffer: a binary buffer (e.g. serialized blob) :return: the first 8 characters of base64 ASCII rendition SHA-1 """ hashed = hashlib.sha1() for buffer in buffers: hashed.update(buffer) return to_ascii(hashed.digest())[:8]
python
def short_hash(*buffers): """ :param buffer: a binary buffer (e.g. serialized blob) :return: the first 8 characters of base64 ASCII rendition SHA-1 """ hashed = hashlib.sha1() for buffer in buffers: hashed.update(buffer) return to_ascii(hashed.digest())[:8]
[ "def", "short_hash", "(", "*", "buffers", ")", ":", "hashed", "=", "hashlib", ".", "sha1", "(", ")", "for", "buffer", "in", "buffers", ":", "hashed", ".", "update", "(", "buffer", ")", "return", "to_ascii", "(", "hashed", ".", "digest", "(", ")", ")"...
:param buffer: a binary buffer (e.g. serialized blob) :return: the first 8 characters of base64 ASCII rendition SHA-1
[ ":", "param", "buffer", ":", "a", "binary", "buffer", "(", "e", ".", "g", ".", "serialized", "blob", ")", ":", "return", ":", "the", "first", "8", "characters", "of", "base64", "ASCII", "rendition", "SHA", "-", "1" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/hash.py#L34-L42
datajoint/datajoint-python
datajoint/connection.py
conn
def conn(host=None, user=None, password=None, init_fun=None, reset=False): """ Returns a persistent connection object to be shared by multiple modules. If the connection is not yet established or reset=True, a new connection is set up. If connection information is not provided, it is taken from config w...
python
def conn(host=None, user=None, password=None, init_fun=None, reset=False): """ Returns a persistent connection object to be shared by multiple modules. If the connection is not yet established or reset=True, a new connection is set up. If connection information is not provided, it is taken from config w...
[ "def", "conn", "(", "host", "=", "None", ",", "user", "=", "None", ",", "password", "=", "None", ",", "init_fun", "=", "None", ",", "reset", "=", "False", ")", ":", "if", "not", "hasattr", "(", "conn", ",", "'connection'", ")", "or", "reset", ":", ...
Returns a persistent connection object to be shared by multiple modules. If the connection is not yet established or reset=True, a new connection is set up. If connection information is not provided, it is taken from config which takes the information from dj_local_conf.json. If the password is not specifie...
[ "Returns", "a", "persistent", "connection", "object", "to", "be", "shared", "by", "multiple", "modules", ".", "If", "the", "connection", "is", "not", "yet", "established", "or", "reset", "=", "True", "a", "new", "connection", "is", "set", "up", ".", "If", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/connection.py#L20-L44
datajoint/datajoint-python
datajoint/connection.py
Connection.connect
def connect(self): """ Connects to the database server. """ with warnings.catch_warnings(): warnings.filterwarnings('ignore', '.*deprecated.*') self._conn = client.connect( init_command=self.init_fun, sql_mode="NO_ZERO_DATE,NO_ZERO_...
python
def connect(self): """ Connects to the database server. """ with warnings.catch_warnings(): warnings.filterwarnings('ignore', '.*deprecated.*') self._conn = client.connect( init_command=self.init_fun, sql_mode="NO_ZERO_DATE,NO_ZERO_...
[ "def", "connect", "(", "self", ")", ":", "with", "warnings", ".", "catch_warnings", "(", ")", ":", "warnings", ".", "filterwarnings", "(", "'ignore'", ",", "'.*deprecated.*'", ")", "self", ".", "_conn", "=", "client", ".", "connect", "(", "init_command", "...
Connects to the database server.
[ "Connects", "to", "the", "database", "server", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/connection.py#L88-L100
datajoint/datajoint-python
datajoint/connection.py
Connection.query
def query(self, query, args=(), as_dict=False, suppress_warnings=True, reconnect=None): """ Execute the specified query and return the tuple generator (cursor). :param query: mysql query :param args: additional arguments for the client.cursor :param as_dict: If as_dict is set to...
python
def query(self, query, args=(), as_dict=False, suppress_warnings=True, reconnect=None): """ Execute the specified query and return the tuple generator (cursor). :param query: mysql query :param args: additional arguments for the client.cursor :param as_dict: If as_dict is set to...
[ "def", "query", "(", "self", ",", "query", ",", "args", "=", "(", ")", ",", "as_dict", "=", "False", ",", "suppress_warnings", "=", "True", ",", "reconnect", "=", "None", ")", ":", "if", "reconnect", "is", "None", ":", "reconnect", "=", "config", "["...
Execute the specified query and return the tuple generator (cursor). :param query: mysql query :param args: additional arguments for the client.cursor :param as_dict: If as_dict is set to True, the returned cursor objects returns query results as dictionary. :par...
[ "Execute", "the", "specified", "query", "and", "return", "the", "tuple", "generator", "(", "cursor", ")", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/connection.py#L125-L168
datajoint/datajoint-python
datajoint/connection.py
Connection.in_transaction
def in_transaction(self): """ :return: True if there is an open transaction. """ self._in_transaction = self._in_transaction and self.is_connected return self._in_transaction
python
def in_transaction(self): """ :return: True if there is an open transaction. """ self._in_transaction = self._in_transaction and self.is_connected return self._in_transaction
[ "def", "in_transaction", "(", "self", ")", ":", "self", ".", "_in_transaction", "=", "self", ".", "_in_transaction", "and", "self", ".", "is_connected", "return", "self", ".", "_in_transaction" ]
:return: True if there is an open transaction.
[ ":", "return", ":", "True", "if", "there", "is", "an", "open", "transaction", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/connection.py#L178-L183
datajoint/datajoint-python
datajoint/connection.py
Connection.start_transaction
def start_transaction(self): """ Starts a transaction error. :raise DataJointError: if there is an ongoing transaction. """ if self.in_transaction: raise DataJointError("Nested connections are not supported.") self.query('START TRANSACTION WITH CONSISTENT SNA...
python
def start_transaction(self): """ Starts a transaction error. :raise DataJointError: if there is an ongoing transaction. """ if self.in_transaction: raise DataJointError("Nested connections are not supported.") self.query('START TRANSACTION WITH CONSISTENT SNA...
[ "def", "start_transaction", "(", "self", ")", ":", "if", "self", ".", "in_transaction", ":", "raise", "DataJointError", "(", "\"Nested connections are not supported.\"", ")", "self", ".", "query", "(", "'START TRANSACTION WITH CONSISTENT SNAPSHOT'", ")", "self", ".", ...
Starts a transaction error. :raise DataJointError: if there is an ongoing transaction.
[ "Starts", "a", "transaction", "error", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/connection.py#L185-L195
datajoint/datajoint-python
datajoint/dependencies.py
Dependencies.load
def load(self): """ Load dependencies for all loaded schemas. This method gets called before any operation that requires dependencies: delete, drop, populate, progress. """ # reload from scratch to prevent duplication of renamed edges self.clear() # load primary...
python
def load(self): """ Load dependencies for all loaded schemas. This method gets called before any operation that requires dependencies: delete, drop, populate, progress. """ # reload from scratch to prevent duplication of renamed edges self.clear() # load primary...
[ "def", "load", "(", "self", ")", ":", "# reload from scratch to prevent duplication of renamed edges", "self", ".", "clear", "(", ")", "# load primary key info", "keys", "=", "self", ".", "_conn", ".", "query", "(", "\"\"\"\n SELECT\n conca...
Load dependencies for all loaded schemas. This method gets called before any operation that requires dependencies: delete, drop, populate, progress.
[ "Load", "dependencies", "for", "all", "loaded", "schemas", ".", "This", "method", "gets", "called", "before", "any", "operation", "that", "requires", "dependencies", ":", "delete", "drop", "populate", "progress", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/dependencies.py#L21-L79
datajoint/datajoint-python
datajoint/dependencies.py
Dependencies.parents
def parents(self, table_name, primary=None): """ :param table_name: `schema`.`table` :param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-...
python
def parents(self, table_name, primary=None): """ :param table_name: `schema`.`table` :param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-...
[ "def", "parents", "(", "self", ",", "table_name", ",", "primary", "=", "None", ")", ":", "return", "dict", "(", "p", "[", ":", ":", "2", "]", "for", "p", "in", "self", ".", "in_edges", "(", "table_name", ",", "data", "=", "True", ")", "if", "prim...
:param table_name: `schema`.`table` :param primary: if None, then all parents are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-primary attribute are considered. :return: di...
[ ":", "param", "table_name", ":", "schema", ".", "table", ":", "param", "primary", ":", "if", "None", "then", "all", "parents", "are", "returned", ".", "If", "True", "then", "only", "foreign", "keys", "composed", "of", "primary", "key", "attributes", "are",...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/dependencies.py#L81-L90
datajoint/datajoint-python
datajoint/dependencies.py
Dependencies.children
def children(self, table_name, primary=None): """ :param table_name: `schema`.`table` :param primary: if None, then all children are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one no...
python
def children(self, table_name, primary=None): """ :param table_name: `schema`.`table` :param primary: if None, then all children are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one no...
[ "def", "children", "(", "self", ",", "table_name", ",", "primary", "=", "None", ")", ":", "return", "dict", "(", "p", "[", "1", ":", "3", "]", "for", "p", "in", "self", ".", "out_edges", "(", "table_name", ",", "data", "=", "True", ")", "if", "pr...
:param table_name: `schema`.`table` :param primary: if None, then all children are returned. If True, then only foreign keys composed of primary key attributes are considered. If False, the only foreign keys including at least one non-primary attribute are considered. :return: d...
[ ":", "param", "table_name", ":", "schema", ".", "table", ":", "param", "primary", ":", "if", "None", "then", "all", "children", "are", "returned", ".", "If", "True", "then", "only", "foreign", "keys", "composed", "of", "primary", "key", "attributes", "are"...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/dependencies.py#L92-L101
datajoint/datajoint-python
datajoint/dependencies.py
Dependencies.descendants
def descendants(self, full_table_name): """ :param full_table_name: In form `schema`.`table_name` :return: all dependent tables sorted in topological order. Self is included. """ nodes = self.subgraph( nx.algorithms.dag.descendants(self, full_table_name)) r...
python
def descendants(self, full_table_name): """ :param full_table_name: In form `schema`.`table_name` :return: all dependent tables sorted in topological order. Self is included. """ nodes = self.subgraph( nx.algorithms.dag.descendants(self, full_table_name)) r...
[ "def", "descendants", "(", "self", ",", "full_table_name", ")", ":", "nodes", "=", "self", ".", "subgraph", "(", "nx", ".", "algorithms", ".", "dag", ".", "descendants", "(", "self", ",", "full_table_name", ")", ")", "return", "[", "full_table_name", "]", ...
:param full_table_name: In form `schema`.`table_name` :return: all dependent tables sorted in topological order. Self is included.
[ ":", "param", "full_table_name", ":", "In", "form", "schema", ".", "table_name", ":", "return", ":", "all", "dependent", "tables", "sorted", "in", "topological", "order", ".", "Self", "is", "included", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/dependencies.py#L103-L112
datajoint/datajoint-python
datajoint/dependencies.py
Dependencies.ancestors
def ancestors(self, full_table_name): """ :param full_table_name: In form `schema`.`table_name` :return: all dependent tables sorted in topological order. Self is included. """ nodes = self.subgraph( nx.algorithms.dag.ancestors(self, full_table_name)) return...
python
def ancestors(self, full_table_name): """ :param full_table_name: In form `schema`.`table_name` :return: all dependent tables sorted in topological order. Self is included. """ nodes = self.subgraph( nx.algorithms.dag.ancestors(self, full_table_name)) return...
[ "def", "ancestors", "(", "self", ",", "full_table_name", ")", ":", "nodes", "=", "self", ".", "subgraph", "(", "nx", ".", "algorithms", ".", "dag", ".", "ancestors", "(", "self", ",", "full_table_name", ")", ")", "return", "[", "full_table_name", "]", "+...
:param full_table_name: In form `schema`.`table_name` :return: all dependent tables sorted in topological order. Self is included.
[ ":", "param", "full_table_name", ":", "In", "form", "schema", ".", "table_name", ":", "return", ":", "all", "dependent", "tables", "sorted", "in", "topological", "order", ".", "Self", "is", "included", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/dependencies.py#L114-L122
datajoint/datajoint-python
datajoint/s3.py
Folder.clean
def clean(self, exclude, max_count=None): """ Delete all objects except for those in the exclude :param exclude: a list of blob_hashes to skip. :param max_count: maximum number of object to delete :return: generator of objects that failed to delete """ return self...
python
def clean(self, exclude, max_count=None): """ Delete all objects except for those in the exclude :param exclude: a list of blob_hashes to skip. :param max_count: maximum number of object to delete :return: generator of objects that failed to delete """ return self...
[ "def", "clean", "(", "self", ",", "exclude", ",", "max_count", "=", "None", ")", ":", "return", "self", ".", "client", ".", "remove_objects", "(", "self", ".", "bucket", ",", "itertools", ".", "islice", "(", "(", "x", ".", "object_name", "for", "x", ...
Delete all objects except for those in the exclude :param exclude: a list of blob_hashes to skip. :param max_count: maximum number of object to delete :return: generator of objects that failed to delete
[ "Delete", "all", "objects", "except", "for", "those", "in", "the", "exclude", ":", "param", "exclude", ":", "a", "list", "of", "blob_hashes", "to", "skip", ".", ":", "param", "max_count", ":", "maximum", "number", "of", "object", "to", "delete", ":", "re...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/s3.py#L33-L42
datajoint/datajoint-python
datajoint/settings.py
Config.save
def save(self, filename, verbose=False): """ Saves the settings in JSON format to the given file path. :param filename: filename of the local JSON settings file. """ with open(filename, 'w') as fid: json.dump(self._conf, fid, indent=4) if verbose: ...
python
def save(self, filename, verbose=False): """ Saves the settings in JSON format to the given file path. :param filename: filename of the local JSON settings file. """ with open(filename, 'w') as fid: json.dump(self._conf, fid, indent=4) if verbose: ...
[ "def", "save", "(", "self", ",", "filename", ",", "verbose", "=", "False", ")", ":", "with", "open", "(", "filename", ",", "'w'", ")", "as", "fid", ":", "json", ".", "dump", "(", "self", ".", "_conf", ",", "fid", ",", "indent", "=", "4", ")", "...
Saves the settings in JSON format to the given file path. :param filename: filename of the local JSON settings file.
[ "Saves", "the", "settings", "in", "JSON", "format", "to", "the", "given", "file", "path", ".", ":", "param", "filename", ":", "filename", "of", "the", "local", "JSON", "settings", "file", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/settings.py#L94-L102
datajoint/datajoint-python
datajoint/settings.py
Config.load
def load(self, filename): """ Updates the setting from config file in JSON format. :param filename: filename of the local JSON settings file. If None, the local config file is used. """ if filename is None: filename = LOCALCONFIG with open(filename, 'r') as fi...
python
def load(self, filename): """ Updates the setting from config file in JSON format. :param filename: filename of the local JSON settings file. If None, the local config file is used. """ if filename is None: filename = LOCALCONFIG with open(filename, 'r') as fi...
[ "def", "load", "(", "self", ",", "filename", ")", ":", "if", "filename", "is", "None", ":", "filename", "=", "LOCALCONFIG", "with", "open", "(", "filename", ",", "'r'", ")", "as", "fid", ":", "self", ".", "_conf", ".", "update", "(", "json", ".", "...
Updates the setting from config file in JSON format. :param filename: filename of the local JSON settings file. If None, the local config file is used.
[ "Updates", "the", "setting", "from", "config", "file", "in", "JSON", "format", ".", ":", "param", "filename", ":", "filename", "of", "the", "local", "JSON", "settings", "file", ".", "If", "None", "the", "local", "config", "file", "is", "used", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/settings.py#L104-L113
datajoint/datajoint-python
datajoint/settings.py
Config.save_global
def save_global(self, verbose=False): """ saves the settings in the global config file """ self.save(os.path.expanduser(os.path.join('~', GLOBALCONFIG)), verbose)
python
def save_global(self, verbose=False): """ saves the settings in the global config file """ self.save(os.path.expanduser(os.path.join('~', GLOBALCONFIG)), verbose)
[ "def", "save_global", "(", "self", ",", "verbose", "=", "False", ")", ":", "self", ".", "save", "(", "os", ".", "path", ".", "expanduser", "(", "os", ".", "path", ".", "join", "(", "'~'", ",", "GLOBALCONFIG", ")", ")", ",", "verbose", ")" ]
saves the settings in the global config file
[ "saves", "the", "settings", "in", "the", "global", "config", "file" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/settings.py#L121-L125
datajoint/datajoint-python
datajoint/heading.py
Attribute.todict
def todict(self): """Convert namedtuple to dict.""" return OrderedDict((name, self[i]) for i, name in enumerate(self._fields))
python
def todict(self): """Convert namedtuple to dict.""" return OrderedDict((name, self[i]) for i, name in enumerate(self._fields))
[ "def", "todict", "(", "self", ")", ":", "return", "OrderedDict", "(", "(", "name", ",", "self", "[", "i", "]", ")", "for", "i", ",", "name", "in", "enumerate", "(", "self", ".", "_fields", ")", ")" ]
Convert namedtuple to dict.
[ "Convert", "namedtuple", "to", "dict", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L20-L22
datajoint/datajoint-python
datajoint/heading.py
Attribute.sql
def sql(self): """ Convert primary key attribute tuple into its SQL CREATE TABLE clause. Default values are not reflected. This is used for declaring foreign keys in referencing tables :return: SQL code """ assert self.in_key and not self.nullable # primary key ...
python
def sql(self): """ Convert primary key attribute tuple into its SQL CREATE TABLE clause. Default values are not reflected. This is used for declaring foreign keys in referencing tables :return: SQL code """ assert self.in_key and not self.nullable # primary key ...
[ "def", "sql", "(", "self", ")", ":", "assert", "self", ".", "in_key", "and", "not", "self", ".", "nullable", "# primary key attributes are never nullable", "return", "'`{name}` {type} NOT NULL COMMENT \"{comment}\"'", ".", "format", "(", "name", "=", "self", ".", "n...
Convert primary key attribute tuple into its SQL CREATE TABLE clause. Default values are not reflected. This is used for declaring foreign keys in referencing tables :return: SQL code
[ "Convert", "primary", "key", "attribute", "tuple", "into", "its", "SQL", "CREATE", "TABLE", "clause", ".", "Default", "values", "are", "not", "reflected", ".", "This", "is", "used", "for", "declaring", "foreign", "keys", "in", "referencing", "tables", ":", "...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L25-L34
datajoint/datajoint-python
datajoint/heading.py
Heading.as_dtype
def as_dtype(self): """ represent the heading as a numpy dtype """ return np.dtype(dict( names=self.names, formats=[v.dtype for v in self.attributes.values()]))
python
def as_dtype(self): """ represent the heading as a numpy dtype """ return np.dtype(dict( names=self.names, formats=[v.dtype for v in self.attributes.values()]))
[ "def", "as_dtype", "(", "self", ")", ":", "return", "np", ".", "dtype", "(", "dict", "(", "names", "=", "self", ".", "names", ",", "formats", "=", "[", "v", ".", "dtype", "for", "v", "in", "self", ".", "attributes", ".", "values", "(", ")", "]", ...
represent the heading as a numpy dtype
[ "represent", "the", "heading", "as", "a", "numpy", "dtype" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L112-L118
datajoint/datajoint-python
datajoint/heading.py
Heading.as_sql
def as_sql(self): """ represent heading as SQL field list """ return ','.join('`%s`' % name if self.attributes[name].sql_expression is None else '%s as `%s`' % (self.attributes[name].sql_expression, name) for name in self.names)
python
def as_sql(self): """ represent heading as SQL field list """ return ','.join('`%s`' % name if self.attributes[name].sql_expression is None else '%s as `%s`' % (self.attributes[name].sql_expression, name) for name in self.names)
[ "def", "as_sql", "(", "self", ")", ":", "return", "','", ".", "join", "(", "'`%s`'", "%", "name", "if", "self", ".", "attributes", "[", "name", "]", ".", "sql_expression", "is", "None", "else", "'%s as `%s`'", "%", "(", "self", ".", "attributes", "[", ...
represent heading as SQL field list
[ "represent", "heading", "as", "SQL", "field", "list" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L121-L127
datajoint/datajoint-python
datajoint/heading.py
Heading.init_from_database
def init_from_database(self, conn, database, table_name): """ initialize heading from a database table. The table must exist already. """ info = conn.query('SHOW TABLE STATUS FROM `{database}` WHERE name="{table_name}"'.format( table_name=table_name, database=database), as_d...
python
def init_from_database(self, conn, database, table_name): """ initialize heading from a database table. The table must exist already. """ info = conn.query('SHOW TABLE STATUS FROM `{database}` WHERE name="{table_name}"'.format( table_name=table_name, database=database), as_d...
[ "def", "init_from_database", "(", "self", ",", "conn", ",", "database", ",", "table_name", ")", ":", "info", "=", "conn", ".", "query", "(", "'SHOW TABLE STATUS FROM `{database}` WHERE name=\"{table_name}\"'", ".", "format", "(", "table_name", "=", "table_name", ","...
initialize heading from a database table. The table must exist already.
[ "initialize", "heading", "from", "a", "database", "table", ".", "The", "table", "must", "exist", "already", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L132-L242
datajoint/datajoint-python
datajoint/heading.py
Heading.project
def project(self, attribute_list, named_attributes=None, force_primary_key=None): """ derive a new heading by selecting, renaming, or computing attributes. In relational algebra these operators are known as project, rename, and extend. :param attribute_list: the full list of existing at...
python
def project(self, attribute_list, named_attributes=None, force_primary_key=None): """ derive a new heading by selecting, renaming, or computing attributes. In relational algebra these operators are known as project, rename, and extend. :param attribute_list: the full list of existing at...
[ "def", "project", "(", "self", ",", "attribute_list", ",", "named_attributes", "=", "None", ",", "force_primary_key", "=", "None", ")", ":", "try", ":", "# check for missing attributes", "raise", "DataJointError", "(", "'Attribute `%s` is not found'", "%", "next", "...
derive a new heading by selecting, renaming, or computing attributes. In relational algebra these operators are known as project, rename, and extend. :param attribute_list: the full list of existing attributes to include :param force_primary_key: attributes to force to be converted to primary ...
[ "derive", "a", "new", "heading", "by", "selecting", "renaming", "or", "computing", "attributes", ".", "In", "relational", "algebra", "these", "operators", "are", "known", "as", "project", "rename", "and", "extend", ".", ":", "param", "attribute_list", ":", "th...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L244-L269
datajoint/datajoint-python
datajoint/heading.py
Heading.join
def join(self, other): """ Join two headings into a new one. It assumes that self and other are headings that share no common dependent attributes. """ return Heading( [self.attributes[name].todict() for name in self.primary_key] + [other.attributes[name]....
python
def join(self, other): """ Join two headings into a new one. It assumes that self and other are headings that share no common dependent attributes. """ return Heading( [self.attributes[name].todict() for name in self.primary_key] + [other.attributes[name]....
[ "def", "join", "(", "self", ",", "other", ")", ":", "return", "Heading", "(", "[", "self", ".", "attributes", "[", "name", "]", ".", "todict", "(", ")", "for", "name", "in", "self", ".", "primary_key", "]", "+", "[", "other", ".", "attributes", "["...
Join two headings into a new one. It assumes that self and other are headings that share no common dependent attributes.
[ "Join", "two", "headings", "into", "a", "new", "one", ".", "It", "assumes", "that", "self", "and", "other", "are", "headings", "that", "share", "no", "common", "dependent", "attributes", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L271-L280
datajoint/datajoint-python
datajoint/heading.py
Heading.make_subquery_heading
def make_subquery_heading(self): """ Create a new heading with removed attribute sql_expressions. Used by subqueries, which resolve the sql_expressions. """ return Heading(dict(v.todict(), sql_expression=None) for v in self.attributes.values())
python
def make_subquery_heading(self): """ Create a new heading with removed attribute sql_expressions. Used by subqueries, which resolve the sql_expressions. """ return Heading(dict(v.todict(), sql_expression=None) for v in self.attributes.values())
[ "def", "make_subquery_heading", "(", "self", ")", ":", "return", "Heading", "(", "dict", "(", "v", ".", "todict", "(", ")", ",", "sql_expression", "=", "None", ")", "for", "v", "in", "self", ".", "attributes", ".", "values", "(", ")", ")" ]
Create a new heading with removed attribute sql_expressions. Used by subqueries, which resolve the sql_expressions.
[ "Create", "a", "new", "heading", "with", "removed", "attribute", "sql_expressions", ".", "Used", "by", "subqueries", "which", "resolve", "the", "sql_expressions", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L282-L287
datajoint/datajoint-python
datajoint/heading.py
Heading.extend_primary_key
def extend_primary_key(self, new_attributes): """ Create a new heading in which the primary key also includes new_attributes. :param new_attributes: new attributes to be added to the primary key. """ try: # check for missing attributes raise DataJointError('Attribute...
python
def extend_primary_key(self, new_attributes): """ Create a new heading in which the primary key also includes new_attributes. :param new_attributes: new attributes to be added to the primary key. """ try: # check for missing attributes raise DataJointError('Attribute...
[ "def", "extend_primary_key", "(", "self", ",", "new_attributes", ")", ":", "try", ":", "# check for missing attributes", "raise", "DataJointError", "(", "'Attribute `%s` is not found'", "%", "next", "(", "a", "for", "a", "in", "new_attributes", "if", "a", "not", "...
Create a new heading in which the primary key also includes new_attributes. :param new_attributes: new attributes to be added to the primary key.
[ "Create", "a", "new", "heading", "in", "which", "the", "primary", "key", "also", "includes", "new_attributes", ".", ":", "param", "new_attributes", ":", "new", "attributes", "to", "be", "added", "to", "the", "primary", "key", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/heading.py#L289-L298
datajoint/datajoint-python
datajoint/blob.py
pack_dict
def pack_dict(obj): """ Write dictionary object as a singular structure array :param obj: dictionary object to serialize. The fields must be simple scalar or an array. """ obj = OrderedDict(obj) blob = b'S' blob += np.array((1, 1), dtype=np.uint64).tostring() blob += np.array(len(obj), d...
python
def pack_dict(obj): """ Write dictionary object as a singular structure array :param obj: dictionary object to serialize. The fields must be simple scalar or an array. """ obj = OrderedDict(obj) blob = b'S' blob += np.array((1, 1), dtype=np.uint64).tostring() blob += np.array(len(obj), d...
[ "def", "pack_dict", "(", "obj", ")", ":", "obj", "=", "OrderedDict", "(", "obj", ")", "blob", "=", "b'S'", "blob", "+=", "np", ".", "array", "(", "(", "1", ",", "1", ")", ",", "dtype", "=", "np", ".", "uint64", ")", ".", "tostring", "(", ")", ...
Write dictionary object as a singular structure array :param obj: dictionary object to serialize. The fields must be simple scalar or an array.
[ "Write", "dictionary", "object", "as", "a", "singular", "structure", "array", ":", "param", "obj", ":", "dictionary", "object", "to", "serialize", ".", "The", "fields", "must", "be", "simple", "scalar", "or", "an", "array", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/blob.py#L280-L299
datajoint/datajoint-python
datajoint/blob.py
BlobReader.squeeze
def squeeze(self, array): """ Simplify the given array as much as possible - squeeze out all singleton dimensions and also convert a zero dimensional array into array scalar """ if not self._squeeze: return array array = array.copy() array = array.sque...
python
def squeeze(self, array): """ Simplify the given array as much as possible - squeeze out all singleton dimensions and also convert a zero dimensional array into array scalar """ if not self._squeeze: return array array = array.copy() array = array.sque...
[ "def", "squeeze", "(", "self", ",", "array", ")", ":", "if", "not", "self", ".", "_squeeze", ":", "return", "array", "array", "=", "array", ".", "copy", "(", ")", "array", "=", "array", ".", "squeeze", "(", ")", "if", "array", ".", "ndim", "==", ...
Simplify the given array as much as possible - squeeze out all singleton dimensions and also convert a zero dimensional array into array scalar
[ "Simplify", "the", "given", "array", "as", "much", "as", "possible", "-", "squeeze", "out", "all", "singleton", "dimensions", "and", "also", "convert", "a", "zero", "dimensional", "array", "into", "array", "scalar" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/blob.py#L152-L163
datajoint/datajoint-python
datajoint/blob.py
BlobReader.read_string
def read_string(self, advance=True): """ Read a string terminated by null byte '\0'. The returned string object is ASCII decoded, and will not include the terminating null byte. """ target = self._blob.find(b'\0', self.pos) assert target >= self._pos data = self._...
python
def read_string(self, advance=True): """ Read a string terminated by null byte '\0'. The returned string object is ASCII decoded, and will not include the terminating null byte. """ target = self._blob.find(b'\0', self.pos) assert target >= self._pos data = self._...
[ "def", "read_string", "(", "self", ",", "advance", "=", "True", ")", ":", "target", "=", "self", ".", "_blob", ".", "find", "(", "b'\\0'", ",", "self", ".", "pos", ")", "assert", "target", ">=", "self", ".", "_pos", "data", "=", "self", ".", "_blob...
Read a string terminated by null byte '\0'. The returned string object is ASCII decoded, and will not include the terminating null byte.
[ "Read", "a", "string", "terminated", "by", "null", "byte", "\\", "0", ".", "The", "returned", "string", "object", "is", "ASCII", "decoded", "and", "will", "not", "include", "the", "terminating", "null", "byte", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/blob.py#L180-L190
datajoint/datajoint-python
datajoint/blob.py
BlobReader.read_value
def read_value(self, dtype='uint64', count=1, advance=True): """ Read one or more scalars of the indicated dtype. Count specifies the number of scalars to be read in. """ data = np.frombuffer(self._blob, dtype=dtype, count=count, offset=self.pos) if advance: #...
python
def read_value(self, dtype='uint64', count=1, advance=True): """ Read one or more scalars of the indicated dtype. Count specifies the number of scalars to be read in. """ data = np.frombuffer(self._blob, dtype=dtype, count=count, offset=self.pos) if advance: #...
[ "def", "read_value", "(", "self", ",", "dtype", "=", "'uint64'", ",", "count", "=", "1", ",", "advance", "=", "True", ")", ":", "data", "=", "np", ".", "frombuffer", "(", "self", ".", "_blob", ",", "dtype", "=", "dtype", ",", "count", "=", "count",...
Read one or more scalars of the indicated dtype. Count specifies the number of scalars to be read in.
[ "Read", "one", "or", "more", "scalars", "of", "the", "indicated", "dtype", ".", "Count", "specifies", "the", "number", "of", "scalars", "to", "be", "read", "in", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/blob.py#L192-L203
datajoint/datajoint-python
datajoint/external.py
ExternalTable.put
def put(self, store, obj): """ put an object in external store """ spec = self._get_store_spec(store) blob = pack(obj) blob_hash = long_hash(blob) + store[len('external-'):] if spec['protocol'] == 'file': folder = os.path.join(spec['location'], self.da...
python
def put(self, store, obj): """ put an object in external store """ spec = self._get_store_spec(store) blob = pack(obj) blob_hash = long_hash(blob) + store[len('external-'):] if spec['protocol'] == 'file': folder = os.path.join(spec['location'], self.da...
[ "def", "put", "(", "self", ",", "store", ",", "obj", ")", ":", "spec", "=", "self", ".", "_get_store_spec", "(", "store", ")", "blob", "=", "pack", "(", "obj", ")", "blob_hash", "=", "long_hash", "(", "blob", ")", "+", "store", "[", "len", "(", "...
put an object in external store
[ "put", "an", "object", "in", "external", "store" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/external.py#L45-L74
datajoint/datajoint-python
datajoint/external.py
ExternalTable.get
def get(self, blob_hash): """ get an object from external store. Does not need to check whether it's in the table. """ if blob_hash is None: return None store = blob_hash[STORE_HASH_LENGTH:] store = 'external' + ('-' if store else '') + store ...
python
def get(self, blob_hash): """ get an object from external store. Does not need to check whether it's in the table. """ if blob_hash is None: return None store = blob_hash[STORE_HASH_LENGTH:] store = 'external' + ('-' if store else '') + store ...
[ "def", "get", "(", "self", ",", "blob_hash", ")", ":", "if", "blob_hash", "is", "None", ":", "return", "None", "store", "=", "blob_hash", "[", "STORE_HASH_LENGTH", ":", "]", "store", "=", "'external'", "+", "(", "'-'", "if", "store", "else", "''", ")",...
get an object from external store. Does not need to check whether it's in the table.
[ "get", "an", "object", "from", "external", "store", ".", "Does", "not", "need", "to", "check", "whether", "it", "s", "in", "the", "table", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/external.py#L76-L118
datajoint/datajoint-python
datajoint/external.py
ExternalTable.references
def references(self): """ :return: generator of referencing table names and their referencing columns """ return self.connection.query(""" SELECT concat('`', table_schema, '`.`', table_name, '`') as referencing_table, column_name FROM information_schema.key_column_usage ...
python
def references(self): """ :return: generator of referencing table names and their referencing columns """ return self.connection.query(""" SELECT concat('`', table_schema, '`.`', table_name, '`') as referencing_table, column_name FROM information_schema.key_column_usage ...
[ "def", "references", "(", "self", ")", ":", "return", "self", ".", "connection", ".", "query", "(", "\"\"\"\n SELECT concat('`', table_schema, '`.`', table_name, '`') as referencing_table, column_name\n FROM information_schema.key_column_usage\n WHERE referenced_table_...
:return: generator of referencing table names and their referencing columns
[ ":", "return", ":", "generator", "of", "referencing", "table", "names", "and", "their", "referencing", "columns" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/external.py#L121-L129
datajoint/datajoint-python
datajoint/external.py
ExternalTable.delete_garbage
def delete_garbage(self): """ Delete items that are no longer referenced. This operation is safe to perform at any time. """ self.connection.query( "DELETE FROM `{db}`.`{tab}` WHERE ".format(tab=self.table_name, db=self.database) + " AND ".join( ...
python
def delete_garbage(self): """ Delete items that are no longer referenced. This operation is safe to perform at any time. """ self.connection.query( "DELETE FROM `{db}`.`{tab}` WHERE ".format(tab=self.table_name, db=self.database) + " AND ".join( ...
[ "def", "delete_garbage", "(", "self", ")", ":", "self", ".", "connection", ".", "query", "(", "\"DELETE FROM `{db}`.`{tab}` WHERE \"", ".", "format", "(", "tab", "=", "self", ".", "table_name", ",", "db", "=", "self", ".", "database", ")", "+", "\" AND \"", ...
Delete items that are no longer referenced. This operation is safe to perform at any time.
[ "Delete", "items", "that", "are", "no", "longer", "referenced", ".", "This", "operation", "is", "safe", "to", "perform", "at", "any", "time", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/external.py#L147-L157
datajoint/datajoint-python
datajoint/external.py
ExternalTable.clean_store
def clean_store(self, store, display_progress=True): """ Clean unused data in an external storage repository from unused blobs. This must be performed after delete_garbage during low-usage periods to reduce risks of data loss. """ spec = self._get_store_spec(store) progre...
python
def clean_store(self, store, display_progress=True): """ Clean unused data in an external storage repository from unused blobs. This must be performed after delete_garbage during low-usage periods to reduce risks of data loss. """ spec = self._get_store_spec(store) progre...
[ "def", "clean_store", "(", "self", ",", "store", ",", "display_progress", "=", "True", ")", ":", "spec", "=", "self", ".", "_get_store_spec", "(", "store", ")", "progress", "=", "tqdm", "if", "display_progress", "else", "lambda", "x", ":", "x", "if", "sp...
Clean unused data in an external storage repository from unused blobs. This must be performed after delete_garbage during low-usage periods to reduce risks of data loss.
[ "Clean", "unused", "data", "in", "an", "external", "storage", "repository", "from", "unused", "blobs", ".", "This", "must", "be", "performed", "after", "delete_garbage", "during", "low", "-", "usage", "periods", "to", "reduce", "risks", "of", "data", "loss", ...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/external.py#L159-L176
datajoint/datajoint-python
datajoint/errors.py
is_connection_error
def is_connection_error(e): """ Checks if error e pertains to a connection issue """ return (isinstance(e, err.InterfaceError) and e.args[0] == "(0, '')") or\ (isinstance(e, err.OperationalError) and e.args[0] in operation_error_codes.values())
python
def is_connection_error(e): """ Checks if error e pertains to a connection issue """ return (isinstance(e, err.InterfaceError) and e.args[0] == "(0, '')") or\ (isinstance(e, err.OperationalError) and e.args[0] in operation_error_codes.values())
[ "def", "is_connection_error", "(", "e", ")", ":", "return", "(", "isinstance", "(", "e", ",", "err", ".", "InterfaceError", ")", "and", "e", ".", "args", "[", "0", "]", "==", "\"(0, '')\"", ")", "or", "(", "isinstance", "(", "e", ",", "err", ".", "...
Checks if error e pertains to a connection issue
[ "Checks", "if", "error", "e", "pertains", "to", "a", "connection", "issue" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/errors.py#L18-L23
datajoint/datajoint-python
datajoint/autopopulate.py
AutoPopulate.key_source
def key_source(self): """ :return: the relation whose primary key values are passed, sequentially, to the ``make`` method when populate() is called. The default value is the join of the parent relations. Users may override to change the granularity or the ...
python
def key_source(self): """ :return: the relation whose primary key values are passed, sequentially, to the ``make`` method when populate() is called. The default value is the join of the parent relations. Users may override to change the granularity or the ...
[ "def", "key_source", "(", "self", ")", ":", "def", "parent_gen", "(", "self", ")", ":", "if", "self", ".", "target", ".", "full_table_name", "not", "in", "self", ".", "connection", ".", "dependencies", ":", "self", ".", "connection", ".", "dependencies", ...
:return: the relation whose primary key values are passed, sequentially, to the ``make`` method when populate() is called. The default value is the join of the parent relations. Users may override to change the granularity or the scope of populate() calls.
[ ":", "return", ":", "the", "relation", "whose", "primary", "key", "values", "are", "passed", "sequentially", "to", "the", "make", "method", "when", "populate", "()", "is", "called", ".", "The", "default", "value", "is", "the", "join", "of", "the", "parent"...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/autopopulate.py#L28-L54
datajoint/datajoint-python
datajoint/autopopulate.py
AutoPopulate._jobs_to_do
def _jobs_to_do(self, restrictions): """ :return: the relation containing the keys to be computed (derived from self.key_source) """ if self.restriction: raise DataJointError('Cannot call populate on a restricted table. ' 'Instead, pass condit...
python
def _jobs_to_do(self, restrictions): """ :return: the relation containing the keys to be computed (derived from self.key_source) """ if self.restriction: raise DataJointError('Cannot call populate on a restricted table. ' 'Instead, pass condit...
[ "def", "_jobs_to_do", "(", "self", ",", "restrictions", ")", ":", "if", "self", ".", "restriction", ":", "raise", "DataJointError", "(", "'Cannot call populate on a restricted table. '", "'Instead, pass conditions to populate() as arguments.'", ")", "todo", "=", "self", "...
:return: the relation containing the keys to be computed (derived from self.key_source)
[ ":", "return", ":", "the", "relation", "containing", "the", "keys", "to", "be", "computed", "(", "derived", "from", "self", ".", "key_source", ")" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/autopopulate.py#L79-L96
datajoint/datajoint-python
datajoint/autopopulate.py
AutoPopulate.populate
def populate(self, *restrictions, suppress_errors=False, return_exception_objects=False, reserve_jobs=False, order="original", limit=None, max_calls=None, display_progress=False): """ rel.populate() calls rel.make(key) for every primary key in self.key_source fo...
python
def populate(self, *restrictions, suppress_errors=False, return_exception_objects=False, reserve_jobs=False, order="original", limit=None, max_calls=None, display_progress=False): """ rel.populate() calls rel.make(key) for every primary key in self.key_source fo...
[ "def", "populate", "(", "self", ",", "*", "restrictions", ",", "suppress_errors", "=", "False", ",", "return_exception_objects", "=", "False", ",", "reserve_jobs", "=", "False", ",", "order", "=", "\"original\"", ",", "limit", "=", "None", ",", "max_calls", ...
rel.populate() calls rel.make(key) for every primary key in self.key_source for which there is not already a tuple in rel. :param restrictions: a list of restrictions each restrict (rel.key_source - target.proj()) :param suppress_errors: if True, do not terminate execution. :param return...
[ "rel", ".", "populate", "()", "calls", "rel", ".", "make", "(", "key", ")", "for", "every", "primary", "key", "in", "self", ".", "key_source", "for", "which", "there", "is", "not", "already", "a", "tuple", "in", "rel", ".", ":", "param", "restrictions"...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/autopopulate.py#L98-L183
datajoint/datajoint-python
datajoint/autopopulate.py
AutoPopulate.progress
def progress(self, *restrictions, display=True): """ report progress of populating the table :return: remaining, total -- tuples to be populated """ todo = self._jobs_to_do(restrictions) total = len(todo) remaining = len(todo - self.target) if display: ...
python
def progress(self, *restrictions, display=True): """ report progress of populating the table :return: remaining, total -- tuples to be populated """ todo = self._jobs_to_do(restrictions) total = len(todo) remaining = len(todo - self.target) if display: ...
[ "def", "progress", "(", "self", ",", "*", "restrictions", ",", "display", "=", "True", ")", ":", "todo", "=", "self", ".", "_jobs_to_do", "(", "restrictions", ")", "total", "=", "len", "(", "todo", ")", "remaining", "=", "len", "(", "todo", "-", "sel...
report progress of populating the table :return: remaining, total -- tuples to be populated
[ "report", "progress", "of", "populating", "the", "table", ":", "return", ":", "remaining", "total", "--", "tuples", "to", "be", "populated" ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/autopopulate.py#L185-L198
datajoint/datajoint-python
datajoint/admin.py
kill
def kill(restriction=None, connection=None): # pragma: no cover """ view and kill database connections. :param restriction: restriction to be applied to processlist :param connection: a datajoint.Connection object. Default calls datajoint.conn() Restrictions are specified as strings and can involv...
python
def kill(restriction=None, connection=None): # pragma: no cover """ view and kill database connections. :param restriction: restriction to be applied to processlist :param connection: a datajoint.Connection object. Default calls datajoint.conn() Restrictions are specified as strings and can involv...
[ "def", "kill", "(", "restriction", "=", "None", ",", "connection", "=", "None", ")", ":", "# pragma: no cover", "if", "connection", "is", "None", ":", "connection", "=", "conn", "(", ")", "query", "=", "'SELECT * FROM information_schema.processlist WHERE id <> CONNE...
view and kill database connections. :param restriction: restriction to be applied to processlist :param connection: a datajoint.Connection object. Default calls datajoint.conn() Restrictions are specified as strings and can involve any of the attributes of information_schema.processlist: ID, USER, HOST...
[ "view", "and", "kill", "database", "connections", ".", ":", "param", "restriction", ":", "restriction", "to", "be", "applied", "to", "processlist", ":", "param", "connection", ":", "a", "datajoint", ".", "Connection", "object", ".", "Default", "calls", "datajo...
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/admin.py#L24-L65
datajoint/datajoint-python
datajoint/user_tables.py
UserTable.table_name
def table_name(cls): """ :returns: the table name of the table formatted for mysql. """ if cls._prefix is None: raise AttributeError('Class prefix is not defined!') return cls._prefix + from_camel_case(cls.__name__)
python
def table_name(cls): """ :returns: the table name of the table formatted for mysql. """ if cls._prefix is None: raise AttributeError('Class prefix is not defined!') return cls._prefix + from_camel_case(cls.__name__)
[ "def", "table_name", "(", "cls", ")", ":", "if", "cls", ".", "_prefix", "is", "None", ":", "raise", "AttributeError", "(", "'Class prefix is not defined!'", ")", "return", "cls", ".", "_prefix", "+", "from_camel_case", "(", "cls", ".", "__name__", ")" ]
:returns: the table name of the table formatted for mysql.
[ ":", "returns", ":", "the", "table", "name", "of", "the", "table", "formatted", "for", "mysql", "." ]
train
https://github.com/datajoint/datajoint-python/blob/4f29bb154a7ed2b8b64b4d3a9c8be4c16b39621c/datajoint/user_tables.py#L85-L91
python-hyper/brotlipy
src/brotli/brotli.py
decompress
def decompress(data): """ Decompress a complete Brotli-compressed string. :param data: A bytestring containing Brotli-compressed data. """ d = Decompressor() data = d.decompress(data) d.finish() return data
python
def decompress(data): """ Decompress a complete Brotli-compressed string. :param data: A bytestring containing Brotli-compressed data. """ d = Decompressor() data = d.decompress(data) d.finish() return data
[ "def", "decompress", "(", "data", ")", ":", "d", "=", "Decompressor", "(", ")", "data", "=", "d", ".", "decompress", "(", "data", ")", "d", ".", "finish", "(", ")", "return", "data" ]
Decompress a complete Brotli-compressed string. :param data: A bytestring containing Brotli-compressed data.
[ "Decompress", "a", "complete", "Brotli", "-", "compressed", "string", "." ]
train
https://github.com/python-hyper/brotlipy/blob/ffddf2ea5adc584c8c353d246bb1077b7e781b63/src/brotli/brotli.py#L82-L91
python-hyper/brotlipy
src/brotli/brotli.py
compress
def compress(data, mode=DEFAULT_MODE, quality=lib.BROTLI_DEFAULT_QUALITY, lgwin=lib.BROTLI_DEFAULT_WINDOW, lgblock=0, dictionary=b''): """ Compress a string using Brotli. .. versionchanged:: 0.5.0 Added ``mode``, ``quality``, `lgwin``,...
python
def compress(data, mode=DEFAULT_MODE, quality=lib.BROTLI_DEFAULT_QUALITY, lgwin=lib.BROTLI_DEFAULT_WINDOW, lgblock=0, dictionary=b''): """ Compress a string using Brotli. .. versionchanged:: 0.5.0 Added ``mode``, ``quality``, `lgwin``,...
[ "def", "compress", "(", "data", ",", "mode", "=", "DEFAULT_MODE", ",", "quality", "=", "lib", ".", "BROTLI_DEFAULT_QUALITY", ",", "lgwin", "=", "lib", ".", "BROTLI_DEFAULT_WINDOW", ",", "lgblock", "=", "0", ",", "dictionary", "=", "b''", ")", ":", "# This ...
Compress a string using Brotli. .. versionchanged:: 0.5.0 Added ``mode``, ``quality``, `lgwin``, ``lgblock``, and ``dictionary`` parameters. :param data: A bytestring containing the data to compress. :type data: ``bytes`` :param mode: The encoder mode. :type mode: :class:`BrotliEnco...
[ "Compress", "a", "string", "using", "Brotli", "." ]
train
https://github.com/python-hyper/brotlipy/blob/ffddf2ea5adc584c8c353d246bb1077b7e781b63/src/brotli/brotli.py#L94-L152
python-hyper/brotlipy
src/brotli/brotli.py
_set_parameter
def _set_parameter(encoder, parameter, parameter_name, val): """ This helper function sets a specific Brotli encoder parameter, checking the return code and raising :class:`Error <brotli.Error>` if it is invalid. """ rc = lib.BrotliEncoderSetParameter(encoder, parameter, val) if parameter =...
python
def _set_parameter(encoder, parameter, parameter_name, val): """ This helper function sets a specific Brotli encoder parameter, checking the return code and raising :class:`Error <brotli.Error>` if it is invalid. """ rc = lib.BrotliEncoderSetParameter(encoder, parameter, val) if parameter =...
[ "def", "_set_parameter", "(", "encoder", ",", "parameter", ",", "parameter_name", ",", "val", ")", ":", "rc", "=", "lib", ".", "BrotliEncoderSetParameter", "(", "encoder", ",", "parameter", ",", "val", ")", "if", "parameter", "==", "lib", ".", "BROTLI_PARAM_...
This helper function sets a specific Brotli encoder parameter, checking the return code and raising :class:`Error <brotli.Error>` if it is invalid.
[ "This", "helper", "function", "sets", "a", "specific", "Brotli", "encoder", "parameter", "checking", "the", "return", "code", "and", "raising", ":", "class", ":", "Error", "<brotli", ".", "Error", ">", "if", "it", "is", "invalid", "." ]
train
https://github.com/python-hyper/brotlipy/blob/ffddf2ea5adc584c8c353d246bb1077b7e781b63/src/brotli/brotli.py#L194-L219
python-hyper/brotlipy
src/brotli/brotli.py
Compressor._compress
def _compress(self, data, operation): """ This private method compresses some data in a given mode. This is used because almost all of the code uses the exact same setup. It wouldn't have to, but it doesn't hurt at all. """ # The 'algorithm' for working out how big to mak...
python
def _compress(self, data, operation): """ This private method compresses some data in a given mode. This is used because almost all of the code uses the exact same setup. It wouldn't have to, but it doesn't hurt at all. """ # The 'algorithm' for working out how big to mak...
[ "def", "_compress", "(", "self", ",", "data", ",", "operation", ")", ":", "# The 'algorithm' for working out how big to make this buffer is from", "# the Brotli source code, brotlimodule.cc.", "original_output_size", "=", "int", "(", "math", ".", "ceil", "(", "len", "(", ...
This private method compresses some data in a given mode. This is used because almost all of the code uses the exact same setup. It wouldn't have to, but it doesn't hurt at all.
[ "This", "private", "method", "compresses", "some", "data", "in", "a", "given", "mode", ".", "This", "is", "used", "because", "almost", "all", "of", "the", "code", "uses", "the", "exact", "same", "setup", ".", "It", "wouldn", "t", "have", "to", "but", "...
train
https://github.com/python-hyper/brotlipy/blob/ffddf2ea5adc584c8c353d246bb1077b7e781b63/src/brotli/brotli.py#L283-L317
python-hyper/brotlipy
src/brotli/brotli.py
Compressor.flush
def flush(self): """ Flush the compressor. This will emit the remaining output data, but will not destroy the compressor. It can be used, for example, to ensure that given chunks of content will decompress immediately. """ chunks = [] chunks.append(self._compress(...
python
def flush(self): """ Flush the compressor. This will emit the remaining output data, but will not destroy the compressor. It can be used, for example, to ensure that given chunks of content will decompress immediately. """ chunks = [] chunks.append(self._compress(...
[ "def", "flush", "(", "self", ")", ":", "chunks", "=", "[", "]", "chunks", ".", "append", "(", "self", ".", "_compress", "(", "b''", ",", "lib", ".", "BROTLI_OPERATION_FLUSH", ")", ")", "while", "lib", ".", "BrotliEncoderHasMoreOutput", "(", "self", ".", ...
Flush the compressor. This will emit the remaining output data, but will not destroy the compressor. It can be used, for example, to ensure that given chunks of content will decompress immediately.
[ "Flush", "the", "compressor", ".", "This", "will", "emit", "the", "remaining", "output", "data", "but", "will", "not", "destroy", "the", "compressor", ".", "It", "can", "be", "used", "for", "example", "to", "ensure", "that", "given", "chunks", "of", "conte...
train
https://github.com/python-hyper/brotlipy/blob/ffddf2ea5adc584c8c353d246bb1077b7e781b63/src/brotli/brotli.py#L330-L342
python-hyper/brotlipy
src/brotli/brotli.py
Compressor.finish
def finish(self): """ Finish the compressor. This will emit the remaining output data and transition the compressor to a completed state. The compressor cannot be used again after this point, and must be replaced. """ chunks = [] while lib.BrotliEncoderIsFinished(...
python
def finish(self): """ Finish the compressor. This will emit the remaining output data and transition the compressor to a completed state. The compressor cannot be used again after this point, and must be replaced. """ chunks = [] while lib.BrotliEncoderIsFinished(...
[ "def", "finish", "(", "self", ")", ":", "chunks", "=", "[", "]", "while", "lib", ".", "BrotliEncoderIsFinished", "(", "self", ".", "_encoder", ")", "==", "lib", ".", "BROTLI_FALSE", ":", "chunks", ".", "append", "(", "self", ".", "_compress", "(", "b''...
Finish the compressor. This will emit the remaining output data and transition the compressor to a completed state. The compressor cannot be used again after this point, and must be replaced.
[ "Finish", "the", "compressor", ".", "This", "will", "emit", "the", "remaining", "output", "data", "and", "transition", "the", "compressor", "to", "a", "completed", "state", ".", "The", "compressor", "cannot", "be", "used", "again", "after", "this", "point", ...
train
https://github.com/python-hyper/brotlipy/blob/ffddf2ea5adc584c8c353d246bb1077b7e781b63/src/brotli/brotli.py#L344-L354
python-hyper/brotlipy
src/brotli/brotli.py
Decompressor.decompress
def decompress(self, data): """ Decompress part of a complete Brotli-compressed string. :param data: A bytestring containing Brotli-compressed data. :returns: A bytestring containing the decompressed data. """ chunks = [] available_in = ffi.new("size_t *", len(d...
python
def decompress(self, data): """ Decompress part of a complete Brotli-compressed string. :param data: A bytestring containing Brotli-compressed data. :returns: A bytestring containing the decompressed data. """ chunks = [] available_in = ffi.new("size_t *", len(d...
[ "def", "decompress", "(", "self", ",", "data", ")", ":", "chunks", "=", "[", "]", "available_in", "=", "ffi", ".", "new", "(", "\"size_t *\"", ",", "len", "(", "data", ")", ")", "in_buffer", "=", "ffi", ".", "new", "(", "\"uint8_t[]\"", ",", "data", ...
Decompress part of a complete Brotli-compressed string. :param data: A bytestring containing Brotli-compressed data. :returns: A bytestring containing the decompressed data.
[ "Decompress", "part", "of", "a", "complete", "Brotli", "-", "compressed", "string", "." ]
train
https://github.com/python-hyper/brotlipy/blob/ffddf2ea5adc584c8c353d246bb1077b7e781b63/src/brotli/brotli.py#L386-L435