id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
42,200
haaksmash/pyutils
utils/dicts/helpers.py
from_keyed_iterable
def from_keyed_iterable(iterable, key, filter_func=None): """Construct a dictionary out of an iterable, using an attribute name as the key. Optionally provide a filter function, to determine what should be kept in the dictionary.""" generated = {} for element in iterable: try: ...
python
def from_keyed_iterable(iterable, key, filter_func=None): """Construct a dictionary out of an iterable, using an attribute name as the key. Optionally provide a filter function, to determine what should be kept in the dictionary.""" generated = {} for element in iterable: try: ...
[ "def", "from_keyed_iterable", "(", "iterable", ",", "key", ",", "filter_func", "=", "None", ")", ":", "generated", "=", "{", "}", "for", "element", "in", "iterable", ":", "try", ":", "k", "=", "getattr", "(", "element", ",", "key", ")", "except", "Attr...
Construct a dictionary out of an iterable, using an attribute name as the key. Optionally provide a filter function, to determine what should be kept in the dictionary.
[ "Construct", "a", "dictionary", "out", "of", "an", "iterable", "using", "an", "attribute", "name", "as", "the", "key", ".", "Optionally", "provide", "a", "filter", "function", "to", "determine", "what", "should", "be", "kept", "in", "the", "dictionary", "." ...
6ba851d11e53812dfc9017537a4f2de198851708
https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dicts/helpers.py#L4-L25
42,201
haaksmash/pyutils
utils/dicts/helpers.py
subtract_by_key
def subtract_by_key(dict_a, dict_b): """given two dicts, a and b, this function returns c = a - b, where a - b is defined as the key difference between a and b. e.g., {1:None, 2:3, 3:"yellow", 4:True} - {2:4, 1:"green"} = {3:"yellow", 4:True} """ difference_dict = {} for key in dic...
python
def subtract_by_key(dict_a, dict_b): """given two dicts, a and b, this function returns c = a - b, where a - b is defined as the key difference between a and b. e.g., {1:None, 2:3, 3:"yellow", 4:True} - {2:4, 1:"green"} = {3:"yellow", 4:True} """ difference_dict = {} for key in dic...
[ "def", "subtract_by_key", "(", "dict_a", ",", "dict_b", ")", ":", "difference_dict", "=", "{", "}", "for", "key", "in", "dict_a", ":", "if", "key", "not", "in", "dict_b", ":", "difference_dict", "[", "key", "]", "=", "dict_a", "[", "key", "]", "return"...
given two dicts, a and b, this function returns c = a - b, where a - b is defined as the key difference between a and b. e.g., {1:None, 2:3, 3:"yellow", 4:True} - {2:4, 1:"green"} = {3:"yellow", 4:True}
[ "given", "two", "dicts", "a", "and", "b", "this", "function", "returns", "c", "=", "a", "-", "b", "where", "a", "-", "b", "is", "defined", "as", "the", "key", "difference", "between", "a", "and", "b", "." ]
6ba851d11e53812dfc9017537a4f2de198851708
https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dicts/helpers.py#L28-L42
42,202
haaksmash/pyutils
utils/dicts/helpers.py
winnow_by_keys
def winnow_by_keys(dct, keys=None, filter_func=None): """separates a dict into has-keys and not-has-keys pairs, using either a list of keys or a filtering function.""" has = {} has_not = {} for key in dct: key_passes_check = False if keys is not None: key_passes_check = ...
python
def winnow_by_keys(dct, keys=None, filter_func=None): """separates a dict into has-keys and not-has-keys pairs, using either a list of keys or a filtering function.""" has = {} has_not = {} for key in dct: key_passes_check = False if keys is not None: key_passes_check = ...
[ "def", "winnow_by_keys", "(", "dct", ",", "keys", "=", "None", ",", "filter_func", "=", "None", ")", ":", "has", "=", "{", "}", "has_not", "=", "{", "}", "for", "key", "in", "dct", ":", "key_passes_check", "=", "False", "if", "keys", "is", "not", "...
separates a dict into has-keys and not-has-keys pairs, using either a list of keys or a filtering function.
[ "separates", "a", "dict", "into", "has", "-", "keys", "and", "not", "-", "has", "-", "keys", "pairs", "using", "either", "a", "list", "of", "keys", "or", "a", "filtering", "function", "." ]
6ba851d11e53812dfc9017537a4f2de198851708
https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dicts/helpers.py#L61-L79
42,203
haaksmash/pyutils
utils/lists.py
flat_map
def flat_map(iterable, func): """func must take an item and return an interable that contains that item. this is flatmap in the classic mode""" results = [] for element in iterable: result = func(element) if len(result) > 0: results.extend(result) return results
python
def flat_map(iterable, func): """func must take an item and return an interable that contains that item. this is flatmap in the classic mode""" results = [] for element in iterable: result = func(element) if len(result) > 0: results.extend(result) return results
[ "def", "flat_map", "(", "iterable", ",", "func", ")", ":", "results", "=", "[", "]", "for", "element", "in", "iterable", ":", "result", "=", "func", "(", "element", ")", "if", "len", "(", "result", ")", ">", "0", ":", "results", ".", "extend", "(",...
func must take an item and return an interable that contains that item. this is flatmap in the classic mode
[ "func", "must", "take", "an", "item", "and", "return", "an", "interable", "that", "contains", "that", "item", ".", "this", "is", "flatmap", "in", "the", "classic", "mode" ]
6ba851d11e53812dfc9017537a4f2de198851708
https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/lists.py#L34-L42
42,204
haaksmash/pyutils
utils/math.py
product
def product(sequence, initial=1): """like the built-in sum, but for multiplication.""" if not isinstance(sequence, collections.Iterable): raise TypeError("'{}' object is not iterable".format(type(sequence).__name__)) return reduce(operator.mul, sequence, initial)
python
def product(sequence, initial=1): """like the built-in sum, but for multiplication.""" if not isinstance(sequence, collections.Iterable): raise TypeError("'{}' object is not iterable".format(type(sequence).__name__)) return reduce(operator.mul, sequence, initial)
[ "def", "product", "(", "sequence", ",", "initial", "=", "1", ")", ":", "if", "not", "isinstance", "(", "sequence", ",", "collections", ".", "Iterable", ")", ":", "raise", "TypeError", "(", "\"'{}' object is not iterable\"", ".", "format", "(", "type", "(", ...
like the built-in sum, but for multiplication.
[ "like", "the", "built", "-", "in", "sum", "but", "for", "multiplication", "." ]
6ba851d11e53812dfc9017537a4f2de198851708
https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/math.py#L11-L16
42,205
haaksmash/pyutils
utils/dates.py
date_from_string
def date_from_string(string, format_string=None): """Runs through a few common string formats for datetimes, and attempts to coerce them into a datetime. Alternatively, format_string can provide either a single string to attempt or an iterable of strings to attempt.""" if isinstance(format_string, ...
python
def date_from_string(string, format_string=None): """Runs through a few common string formats for datetimes, and attempts to coerce them into a datetime. Alternatively, format_string can provide either a single string to attempt or an iterable of strings to attempt.""" if isinstance(format_string, ...
[ "def", "date_from_string", "(", "string", ",", "format_string", "=", "None", ")", ":", "if", "isinstance", "(", "format_string", ",", "str", ")", ":", "return", "datetime", ".", "datetime", ".", "strptime", "(", "string", ",", "format_string", ")", ".", "d...
Runs through a few common string formats for datetimes, and attempts to coerce them into a datetime. Alternatively, format_string can provide either a single string to attempt or an iterable of strings to attempt.
[ "Runs", "through", "a", "few", "common", "string", "formats", "for", "datetimes", "and", "attempts", "to", "coerce", "them", "into", "a", "datetime", ".", "Alternatively", "format_string", "can", "provide", "either", "a", "single", "string", "to", "attempt", "...
6ba851d11e53812dfc9017537a4f2de198851708
https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dates.py#L5-L28
42,206
haaksmash/pyutils
utils/dates.py
to_datetime
def to_datetime(plain_date, hours=0, minutes=0, seconds=0, ms=0): """given a datetime.date, gives back a datetime.datetime""" # don't mess with datetimes if isinstance(plain_date, datetime.datetime): return plain_date return datetime.datetime( plain_date.year, plain_date.month, ...
python
def to_datetime(plain_date, hours=0, minutes=0, seconds=0, ms=0): """given a datetime.date, gives back a datetime.datetime""" # don't mess with datetimes if isinstance(plain_date, datetime.datetime): return plain_date return datetime.datetime( plain_date.year, plain_date.month, ...
[ "def", "to_datetime", "(", "plain_date", ",", "hours", "=", "0", ",", "minutes", "=", "0", ",", "seconds", "=", "0", ",", "ms", "=", "0", ")", ":", "# don't mess with datetimes", "if", "isinstance", "(", "plain_date", ",", "datetime", ".", "datetime", ")...
given a datetime.date, gives back a datetime.datetime
[ "given", "a", "datetime", ".", "date", "gives", "back", "a", "datetime", ".", "datetime" ]
6ba851d11e53812dfc9017537a4f2de198851708
https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dates.py#L31-L44
42,207
haaksmash/pyutils
utils/dates.py
TimePeriod.get_containing_period
def get_containing_period(cls, *periods): """Given a bunch of TimePeriods, return a TimePeriod that most closely contains them.""" if any(not isinstance(period, TimePeriod) for period in periods): raise TypeError("periods must all be TimePeriods: {}".format(periods)) latest...
python
def get_containing_period(cls, *periods): """Given a bunch of TimePeriods, return a TimePeriod that most closely contains them.""" if any(not isinstance(period, TimePeriod) for period in periods): raise TypeError("periods must all be TimePeriods: {}".format(periods)) latest...
[ "def", "get_containing_period", "(", "cls", ",", "*", "periods", ")", ":", "if", "any", "(", "not", "isinstance", "(", "period", ",", "TimePeriod", ")", "for", "period", "in", "periods", ")", ":", "raise", "TypeError", "(", "\"periods must all be TimePeriods: ...
Given a bunch of TimePeriods, return a TimePeriod that most closely contains them.
[ "Given", "a", "bunch", "of", "TimePeriods", "return", "a", "TimePeriod", "that", "most", "closely", "contains", "them", "." ]
6ba851d11e53812dfc9017537a4f2de198851708
https://github.com/haaksmash/pyutils/blob/6ba851d11e53812dfc9017537a4f2de198851708/utils/dates.py#L133-L155
42,208
major/supernova
supernova/credentials.py
get_user_password
def get_user_password(env, param, force=False): """ Allows the user to print the credential for a particular keyring entry to the screen """ username = utils.assemble_username(env, param) if not utils.confirm_credential_display(force): return # Retrieve the credential from the keyc...
python
def get_user_password(env, param, force=False): """ Allows the user to print the credential for a particular keyring entry to the screen """ username = utils.assemble_username(env, param) if not utils.confirm_credential_display(force): return # Retrieve the credential from the keyc...
[ "def", "get_user_password", "(", "env", ",", "param", ",", "force", "=", "False", ")", ":", "username", "=", "utils", ".", "assemble_username", "(", "env", ",", "param", ")", "if", "not", "utils", ".", "confirm_credential_display", "(", "force", ")", ":", ...
Allows the user to print the credential for a particular keyring entry to the screen
[ "Allows", "the", "user", "to", "print", "the", "credential", "for", "a", "particular", "keyring", "entry", "to", "the", "screen" ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L34-L50
42,209
major/supernova
supernova/credentials.py
password_get
def password_get(username=None): """ Retrieves a password from the keychain based on the environment and configuration parameter pair. If this fails, None is returned. """ password = keyring.get_password('supernova', username) if password is None: split_username = tuple(username.spl...
python
def password_get(username=None): """ Retrieves a password from the keychain based on the environment and configuration parameter pair. If this fails, None is returned. """ password = keyring.get_password('supernova', username) if password is None: split_username = tuple(username.spl...
[ "def", "password_get", "(", "username", "=", "None", ")", ":", "password", "=", "keyring", ".", "get_password", "(", "'supernova'", ",", "username", ")", "if", "password", "is", "None", ":", "split_username", "=", "tuple", "(", "username", ".", "split", "(...
Retrieves a password from the keychain based on the environment and configuration parameter pair. If this fails, None is returned.
[ "Retrieves", "a", "password", "from", "the", "keychain", "based", "on", "the", "environment", "and", "configuration", "parameter", "pair", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L73-L87
42,210
major/supernova
supernova/credentials.py
set_user_password
def set_user_password(environment, parameter, password): """ Sets a user's password in the keyring storage """ username = '%s:%s' % (environment, parameter) return password_set(username, password)
python
def set_user_password(environment, parameter, password): """ Sets a user's password in the keyring storage """ username = '%s:%s' % (environment, parameter) return password_set(username, password)
[ "def", "set_user_password", "(", "environment", ",", "parameter", ",", "password", ")", ":", "username", "=", "'%s:%s'", "%", "(", "environment", ",", "parameter", ")", "return", "password_set", "(", "username", ",", "password", ")" ]
Sets a user's password in the keyring storage
[ "Sets", "a", "user", "s", "password", "in", "the", "keyring", "storage" ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L90-L95
42,211
major/supernova
supernova/credentials.py
password_set
def password_set(username=None, password=None): """ Stores a password in a keychain for a particular environment and configuration parameter pair. """ result = keyring.set_password('supernova', username, password) # NOTE: keyring returns None when the storage is successful. That's weird. i...
python
def password_set(username=None, password=None): """ Stores a password in a keychain for a particular environment and configuration parameter pair. """ result = keyring.set_password('supernova', username, password) # NOTE: keyring returns None when the storage is successful. That's weird. i...
[ "def", "password_set", "(", "username", "=", "None", ",", "password", "=", "None", ")", ":", "result", "=", "keyring", ".", "set_password", "(", "'supernova'", ",", "username", ",", "password", ")", "# NOTE: keyring returns None when the storage is successful. That's...
Stores a password in a keychain for a particular environment and configuration parameter pair.
[ "Stores", "a", "password", "in", "a", "keychain", "for", "a", "particular", "environment", "and", "configuration", "parameter", "pair", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L98-L109
42,212
major/supernova
supernova/credentials.py
prep_shell_environment
def prep_shell_environment(nova_env, nova_creds): """ Appends new variables to the current shell environment temporarily. """ new_env = {} for key, value in prep_nova_creds(nova_env, nova_creds): if type(value) == six.binary_type: value = value.decode() new_env[key] = va...
python
def prep_shell_environment(nova_env, nova_creds): """ Appends new variables to the current shell environment temporarily. """ new_env = {} for key, value in prep_nova_creds(nova_env, nova_creds): if type(value) == six.binary_type: value = value.decode() new_env[key] = va...
[ "def", "prep_shell_environment", "(", "nova_env", ",", "nova_creds", ")", ":", "new_env", "=", "{", "}", "for", "key", ",", "value", "in", "prep_nova_creds", "(", "nova_env", ",", "nova_creds", ")", ":", "if", "type", "(", "value", ")", "==", "six", ".",...
Appends new variables to the current shell environment temporarily.
[ "Appends", "new", "variables", "to", "the", "current", "shell", "environment", "temporarily", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L112-L123
42,213
major/supernova
supernova/credentials.py
prep_nova_creds
def prep_nova_creds(nova_env, nova_creds): """ Finds relevant config options in the supernova config and cleans them up for novaclient. """ try: raw_creds = dict(nova_creds.get('DEFAULT', {}), **nova_creds[nova_env]) except KeyError: msg = "{0} was not found in your supernova con...
python
def prep_nova_creds(nova_env, nova_creds): """ Finds relevant config options in the supernova config and cleans them up for novaclient. """ try: raw_creds = dict(nova_creds.get('DEFAULT', {}), **nova_creds[nova_env]) except KeyError: msg = "{0} was not found in your supernova con...
[ "def", "prep_nova_creds", "(", "nova_env", ",", "nova_creds", ")", ":", "try", ":", "raw_creds", "=", "dict", "(", "nova_creds", ".", "get", "(", "'DEFAULT'", ",", "{", "}", ")", ",", "*", "*", "nova_creds", "[", "nova_env", "]", ")", "except", "KeyErr...
Finds relevant config options in the supernova config and cleans them up for novaclient.
[ "Finds", "relevant", "config", "options", "in", "the", "supernova", "config", "and", "cleans", "them", "up", "for", "novaclient", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/credentials.py#L126-L162
42,214
major/supernova
supernova/config.py
load_config
def load_config(config_file_override=False): """ Pulls the supernova configuration file and reads it """ supernova_config = get_config_file(config_file_override) supernova_config_dir = get_config_directory(config_file_override) if not supernova_config and not supernova_config_dir: raise...
python
def load_config(config_file_override=False): """ Pulls the supernova configuration file and reads it """ supernova_config = get_config_file(config_file_override) supernova_config_dir = get_config_directory(config_file_override) if not supernova_config and not supernova_config_dir: raise...
[ "def", "load_config", "(", "config_file_override", "=", "False", ")", ":", "supernova_config", "=", "get_config_file", "(", "config_file_override", ")", "supernova_config_dir", "=", "get_config_directory", "(", "config_file_override", ")", "if", "not", "supernova_config",...
Pulls the supernova configuration file and reads it
[ "Pulls", "the", "supernova", "configuration", "file", "and", "reads", "it" ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/config.py#L40-L69
42,215
major/supernova
supernova/config.py
get_config_file
def get_config_file(override_files=False): """ Looks for the most specific configuration file available. An override can be provided as a string if needed. """ if override_files: if isinstance(override_files, six.string_types): possible_configs = [override_files] else: ...
python
def get_config_file(override_files=False): """ Looks for the most specific configuration file available. An override can be provided as a string if needed. """ if override_files: if isinstance(override_files, six.string_types): possible_configs = [override_files] else: ...
[ "def", "get_config_file", "(", "override_files", "=", "False", ")", ":", "if", "override_files", ":", "if", "isinstance", "(", "override_files", ",", "six", ".", "string_types", ")", ":", "possible_configs", "=", "[", "override_files", "]", "else", ":", "raise...
Looks for the most specific configuration file available. An override can be provided as a string if needed.
[ "Looks", "for", "the", "most", "specific", "configuration", "file", "available", ".", "An", "override", "can", "be", "provided", "as", "a", "string", "if", "needed", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/config.py#L72-L93
42,216
major/supernova
supernova/config.py
get_config_directory
def get_config_directory(override_files=False): """ Looks for the most specific configuration directory possible, in order to load individual configuration files. """ if override_files: possible_dirs = [override_files] else: xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or...
python
def get_config_directory(override_files=False): """ Looks for the most specific configuration directory possible, in order to load individual configuration files. """ if override_files: possible_dirs = [override_files] else: xdg_config_home = os.environ.get('XDG_CONFIG_HOME') or...
[ "def", "get_config_directory", "(", "override_files", "=", "False", ")", ":", "if", "override_files", ":", "possible_dirs", "=", "[", "override_files", "]", "else", ":", "xdg_config_home", "=", "os", ".", "environ", ".", "get", "(", "'XDG_CONFIG_HOME'", ")", "...
Looks for the most specific configuration directory possible, in order to load individual configuration files.
[ "Looks", "for", "the", "most", "specific", "configuration", "directory", "possible", "in", "order", "to", "load", "individual", "configuration", "files", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/config.py#L96-L115
42,217
major/supernova
supernova/supernova.py
execute_executable
def execute_executable(nova_args, env_vars): """ Executes the executable given by the user. Hey, I know this method has a silly name, but I write the code here and I'm silly. """ process = subprocess.Popen(nova_args, stdout=sys.stdout, ...
python
def execute_executable(nova_args, env_vars): """ Executes the executable given by the user. Hey, I know this method has a silly name, but I write the code here and I'm silly. """ process = subprocess.Popen(nova_args, stdout=sys.stdout, ...
[ "def", "execute_executable", "(", "nova_args", ",", "env_vars", ")", ":", "process", "=", "subprocess", ".", "Popen", "(", "nova_args", ",", "stdout", "=", "sys", ".", "stdout", ",", "stderr", "=", "subprocess", ".", "PIPE", ",", "env", "=", "env_vars", ...
Executes the executable given by the user. Hey, I know this method has a silly name, but I write the code here and I'm silly.
[ "Executes", "the", "executable", "given", "by", "the", "user", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L32-L44
42,218
major/supernova
supernova/supernova.py
check_for_debug
def check_for_debug(supernova_args, nova_args): """ If the user wanted to run the executable with debugging enabled, we need to apply the correct arguments to the executable. Heat is a corner case since it uses -d instead of --debug. """ # Heat requires special handling for debug arguments ...
python
def check_for_debug(supernova_args, nova_args): """ If the user wanted to run the executable with debugging enabled, we need to apply the correct arguments to the executable. Heat is a corner case since it uses -d instead of --debug. """ # Heat requires special handling for debug arguments ...
[ "def", "check_for_debug", "(", "supernova_args", ",", "nova_args", ")", ":", "# Heat requires special handling for debug arguments", "if", "supernova_args", "[", "'debug'", "]", "and", "supernova_args", "[", "'executable'", "]", "==", "'heat'", ":", "nova_args", ".", ...
If the user wanted to run the executable with debugging enabled, we need to apply the correct arguments to the executable. Heat is a corner case since it uses -d instead of --debug.
[ "If", "the", "user", "wanted", "to", "run", "the", "executable", "with", "debugging", "enabled", "we", "need", "to", "apply", "the", "correct", "arguments", "to", "the", "executable", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L47-L60
42,219
major/supernova
supernova/supernova.py
check_for_executable
def check_for_executable(supernova_args, env_vars): """ It's possible that a user might set their custom executable via an environment variable. If we detect one, we should add it to supernova's arguments ONLY IF an executable wasn't set on the command line. The command line executable must take p...
python
def check_for_executable(supernova_args, env_vars): """ It's possible that a user might set their custom executable via an environment variable. If we detect one, we should add it to supernova's arguments ONLY IF an executable wasn't set on the command line. The command line executable must take p...
[ "def", "check_for_executable", "(", "supernova_args", ",", "env_vars", ")", ":", "exe", "=", "supernova_args", ".", "get", "(", "'executable'", ",", "'default'", ")", "if", "exe", "!=", "'default'", ":", "return", "supernova_args", "if", "'OS_EXECUTABLE'", "in",...
It's possible that a user might set their custom executable via an environment variable. If we detect one, we should add it to supernova's arguments ONLY IF an executable wasn't set on the command line. The command line executable must take priority.
[ "It", "s", "possible", "that", "a", "user", "might", "set", "their", "custom", "executable", "via", "an", "environment", "variable", ".", "If", "we", "detect", "one", "we", "should", "add", "it", "to", "supernova", "s", "arguments", "ONLY", "IF", "an", "...
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L63-L77
42,220
major/supernova
supernova/supernova.py
check_for_bypass_url
def check_for_bypass_url(raw_creds, nova_args): """ Return a list of extra args that need to be passed on cmdline to nova. """ if 'BYPASS_URL' in raw_creds.keys(): bypass_args = ['--bypass-url', raw_creds['BYPASS_URL']] nova_args = bypass_args + nova_args return nova_args
python
def check_for_bypass_url(raw_creds, nova_args): """ Return a list of extra args that need to be passed on cmdline to nova. """ if 'BYPASS_URL' in raw_creds.keys(): bypass_args = ['--bypass-url', raw_creds['BYPASS_URL']] nova_args = bypass_args + nova_args return nova_args
[ "def", "check_for_bypass_url", "(", "raw_creds", ",", "nova_args", ")", ":", "if", "'BYPASS_URL'", "in", "raw_creds", ".", "keys", "(", ")", ":", "bypass_args", "=", "[", "'--bypass-url'", ",", "raw_creds", "[", "'BYPASS_URL'", "]", "]", "nova_args", "=", "b...
Return a list of extra args that need to be passed on cmdline to nova.
[ "Return", "a", "list", "of", "extra", "args", "that", "need", "to", "be", "passed", "on", "cmdline", "to", "nova", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L80-L88
42,221
major/supernova
supernova/supernova.py
run_command
def run_command(nova_creds, nova_args, supernova_args): """ Sets the environment variables for the executable, runs the executable, and handles the output. """ nova_env = supernova_args['nova_env'] # (gtmanfred) make a copy of this object. If we don't copy it, the insert # to 0 happens mult...
python
def run_command(nova_creds, nova_args, supernova_args): """ Sets the environment variables for the executable, runs the executable, and handles the output. """ nova_env = supernova_args['nova_env'] # (gtmanfred) make a copy of this object. If we don't copy it, the insert # to 0 happens mult...
[ "def", "run_command", "(", "nova_creds", ",", "nova_args", ",", "supernova_args", ")", ":", "nova_env", "=", "supernova_args", "[", "'nova_env'", "]", "# (gtmanfred) make a copy of this object. If we don't copy it, the insert", "# to 0 happens multiple times because it is the same...
Sets the environment variables for the executable, runs the executable, and handles the output.
[ "Sets", "the", "environment", "variables", "for", "the", "executable", "runs", "the", "executable", "and", "handles", "the", "output", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/supernova.py#L106-L150
42,222
major/supernova
supernova/utils.py
check_environment_presets
def check_environment_presets(): """ Checks for environment variables that can cause problems with supernova """ presets = [x for x in os.environ.copy().keys() if x.startswith('NOVA_') or x.startswith('OS_')] if len(presets) < 1: return True else: click.echo("_" * ...
python
def check_environment_presets(): """ Checks for environment variables that can cause problems with supernova """ presets = [x for x in os.environ.copy().keys() if x.startswith('NOVA_') or x.startswith('OS_')] if len(presets) < 1: return True else: click.echo("_" * ...
[ "def", "check_environment_presets", "(", ")", ":", "presets", "=", "[", "x", "for", "x", "in", "os", ".", "environ", ".", "copy", "(", ")", ".", "keys", "(", ")", "if", "x", ".", "startswith", "(", "'NOVA_'", ")", "or", "x", ".", "startswith", "(",...
Checks for environment variables that can cause problems with supernova
[ "Checks", "for", "environment", "variables", "that", "can", "cause", "problems", "with", "supernova" ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/utils.py#L29-L44
42,223
major/supernova
supernova/utils.py
get_envs_in_group
def get_envs_in_group(group_name, nova_creds): """ Takes a group_name and finds any environments that have a SUPERNOVA_GROUP configuration line that matches the group_name. """ envs = [] for key, value in nova_creds.items(): supernova_groups = value.get('SUPERNOVA_GROUP', []) if ...
python
def get_envs_in_group(group_name, nova_creds): """ Takes a group_name and finds any environments that have a SUPERNOVA_GROUP configuration line that matches the group_name. """ envs = [] for key, value in nova_creds.items(): supernova_groups = value.get('SUPERNOVA_GROUP', []) if ...
[ "def", "get_envs_in_group", "(", "group_name", ",", "nova_creds", ")", ":", "envs", "=", "[", "]", "for", "key", ",", "value", "in", "nova_creds", ".", "items", "(", ")", ":", "supernova_groups", "=", "value", ".", "get", "(", "'SUPERNOVA_GROUP'", ",", "...
Takes a group_name and finds any environments that have a SUPERNOVA_GROUP configuration line that matches the group_name.
[ "Takes", "a", "group_name", "and", "finds", "any", "environments", "that", "have", "a", "SUPERNOVA_GROUP", "configuration", "line", "that", "matches", "the", "group_name", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/utils.py#L59-L73
42,224
major/supernova
supernova/utils.py
is_valid_group
def is_valid_group(group_name, nova_creds): """ Checks to see if the configuration file contains a SUPERNOVA_GROUP configuration option. """ valid_groups = [] for key, value in nova_creds.items(): supernova_groups = value.get('SUPERNOVA_GROUP', []) if hasattr(supernova_groups, 's...
python
def is_valid_group(group_name, nova_creds): """ Checks to see if the configuration file contains a SUPERNOVA_GROUP configuration option. """ valid_groups = [] for key, value in nova_creds.items(): supernova_groups = value.get('SUPERNOVA_GROUP', []) if hasattr(supernova_groups, 's...
[ "def", "is_valid_group", "(", "group_name", ",", "nova_creds", ")", ":", "valid_groups", "=", "[", "]", "for", "key", ",", "value", "in", "nova_creds", ".", "items", "(", ")", ":", "supernova_groups", "=", "value", ".", "get", "(", "'SUPERNOVA_GROUP'", ","...
Checks to see if the configuration file contains a SUPERNOVA_GROUP configuration option.
[ "Checks", "to", "see", "if", "the", "configuration", "file", "contains", "a", "SUPERNOVA_GROUP", "configuration", "option", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/utils.py#L87-L102
42,225
major/supernova
supernova/utils.py
rm_prefix
def rm_prefix(name): """ Removes nova_ os_ novaclient_ prefix from string. """ if name.startswith('nova_'): return name[5:] elif name.startswith('novaclient_'): return name[11:] elif name.startswith('os_'): return name[3:] else: return name
python
def rm_prefix(name): """ Removes nova_ os_ novaclient_ prefix from string. """ if name.startswith('nova_'): return name[5:] elif name.startswith('novaclient_'): return name[11:] elif name.startswith('os_'): return name[3:] else: return name
[ "def", "rm_prefix", "(", "name", ")", ":", "if", "name", ".", "startswith", "(", "'nova_'", ")", ":", "return", "name", "[", "5", ":", "]", "elif", "name", ".", "startswith", "(", "'novaclient_'", ")", ":", "return", "name", "[", "11", ":", "]", "e...
Removes nova_ os_ novaclient_ prefix from string.
[ "Removes", "nova_", "os_", "novaclient_", "prefix", "from", "string", "." ]
4a217ae53c1c05567014b047c0b6b9dea2d383b3
https://github.com/major/supernova/blob/4a217ae53c1c05567014b047c0b6b9dea2d383b3/supernova/utils.py#L105-L116
42,226
corydolphin/flask-jsonpify
flask_jsonpify.py
__pad
def __pad(strdata): """ Pads `strdata` with a Request's callback argument, if specified, or does nothing. """ if request.args.get('callback'): return "%s(%s);" % (request.args.get('callback'), strdata) else: return strdata
python
def __pad(strdata): """ Pads `strdata` with a Request's callback argument, if specified, or does nothing. """ if request.args.get('callback'): return "%s(%s);" % (request.args.get('callback'), strdata) else: return strdata
[ "def", "__pad", "(", "strdata", ")", ":", "if", "request", ".", "args", ".", "get", "(", "'callback'", ")", ":", "return", "\"%s(%s);\"", "%", "(", "request", ".", "args", ".", "get", "(", "'callback'", ")", ",", "strdata", ")", "else", ":", "return"...
Pads `strdata` with a Request's callback argument, if specified, or does nothing.
[ "Pads", "strdata", "with", "a", "Request", "s", "callback", "argument", "if", "specified", "or", "does", "nothing", "." ]
a875ebe9b8e5bd74b8b44058aa36b099fa6bc84f
https://github.com/corydolphin/flask-jsonpify/blob/a875ebe9b8e5bd74b8b44058aa36b099fa6bc84f/flask_jsonpify.py#L4-L11
42,227
corydolphin/flask-jsonpify
flask_jsonpify.py
__dumps
def __dumps(*args, **kwargs): """ Serializes `args` and `kwargs` as JSON. Supports serializing an array as the top-level object, if it is the only argument. """ indent = None if (current_app.config.get('JSONIFY_PRETTYPRINT_REGULAR', False) and not request.is_xhr): indent =...
python
def __dumps(*args, **kwargs): """ Serializes `args` and `kwargs` as JSON. Supports serializing an array as the top-level object, if it is the only argument. """ indent = None if (current_app.config.get('JSONIFY_PRETTYPRINT_REGULAR', False) and not request.is_xhr): indent =...
[ "def", "__dumps", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "indent", "=", "None", "if", "(", "current_app", ".", "config", ".", "get", "(", "'JSONIFY_PRETTYPRINT_REGULAR'", ",", "False", ")", "and", "not", "request", ".", "is_xhr", ")", ":"...
Serializes `args` and `kwargs` as JSON. Supports serializing an array as the top-level object, if it is the only argument.
[ "Serializes", "args", "and", "kwargs", "as", "JSON", ".", "Supports", "serializing", "an", "array", "as", "the", "top", "-", "level", "object", "if", "it", "is", "the", "only", "argument", "." ]
a875ebe9b8e5bd74b8b44058aa36b099fa6bc84f
https://github.com/corydolphin/flask-jsonpify/blob/a875ebe9b8e5bd74b8b44058aa36b099fa6bc84f/flask_jsonpify.py#L21-L30
42,228
frejanordsiek/hdf5storage
hdf5storage/Marshallers.py
TypeMarshaller.update_type_lookups
def update_type_lookups(self): """ Update type and typestring lookup dicts. Must be called once the ``types`` and ``python_type_strings`` attributes are set so that ``type_to_typestring`` and ``typestring_to_type`` are constructed. .. versionadded:: 0.2 Notes -...
python
def update_type_lookups(self): """ Update type and typestring lookup dicts. Must be called once the ``types`` and ``python_type_strings`` attributes are set so that ``type_to_typestring`` and ``typestring_to_type`` are constructed. .. versionadded:: 0.2 Notes -...
[ "def", "update_type_lookups", "(", "self", ")", ":", "self", ".", "type_to_typestring", "=", "dict", "(", "zip", "(", "self", ".", "types", ",", "self", ".", "python_type_strings", ")", ")", "self", ".", "typestring_to_type", "=", "dict", "(", "zip", "(", ...
Update type and typestring lookup dicts. Must be called once the ``types`` and ``python_type_strings`` attributes are set so that ``type_to_typestring`` and ``typestring_to_type`` are constructed. .. versionadded:: 0.2 Notes ----- Subclasses need to call this f...
[ "Update", "type", "and", "typestring", "lookup", "dicts", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/Marshallers.py#L245-L262
42,229
frejanordsiek/hdf5storage
hdf5storage/Marshallers.py
TypeMarshaller.get_type_string
def get_type_string(self, data, type_string): """ Gets type string. Finds the type string for 'data' contained in ``python_type_strings`` using its ``type``. Non-``None`` 'type_string` overrides whatever type string is looked up. The override makes it easier for subclasses to co...
python
def get_type_string(self, data, type_string): """ Gets type string. Finds the type string for 'data' contained in ``python_type_strings`` using its ``type``. Non-``None`` 'type_string` overrides whatever type string is looked up. The override makes it easier for subclasses to co...
[ "def", "get_type_string", "(", "self", ",", "data", ",", "type_string", ")", ":", "if", "type_string", "is", "not", "None", ":", "return", "type_string", "else", ":", "tp", "=", "type", "(", "data", ")", "try", ":", "return", "self", ".", "type_to_typest...
Gets type string. Finds the type string for 'data' contained in ``python_type_strings`` using its ``type``. Non-``None`` 'type_string` overrides whatever type string is looked up. The override makes it easier for subclasses to convert something that the parent marshaller can wri...
[ "Gets", "type", "string", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/Marshallers.py#L264-L301
42,230
frejanordsiek/hdf5storage
hdf5storage/Marshallers.py
TypeMarshaller.write
def write(self, f, grp, name, data, type_string, options): """ Writes an object's metadata to file. Writes the Python object 'data' to 'name' in h5py.Group 'grp'. .. versionchanged:: 0.2 Arguements changed. Parameters ---------- f : h5py.File The...
python
def write(self, f, grp, name, data, type_string, options): """ Writes an object's metadata to file. Writes the Python object 'data' to 'name' in h5py.Group 'grp'. .. versionchanged:: 0.2 Arguements changed. Parameters ---------- f : h5py.File The...
[ "def", "write", "(", "self", ",", "f", ",", "grp", ",", "name", ",", "data", ",", "type_string", ",", "options", ")", ":", "raise", "NotImplementedError", "(", "'Can'", "'t write data type: '", "+", "str", "(", "type", "(", "data", ")", ")", ")" ]
Writes an object's metadata to file. Writes the Python object 'data' to 'name' in h5py.Group 'grp'. .. versionchanged:: 0.2 Arguements changed. Parameters ---------- f : h5py.File The HDF5 file handle that is open. grp : h5py.Group or h5py.File ...
[ "Writes", "an", "object", "s", "metadata", "to", "file", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/Marshallers.py#L303-L348
42,231
frejanordsiek/hdf5storage
hdf5storage/Marshallers.py
TypeMarshaller.write_metadata
def write_metadata(self, f, dsetgrp, data, type_string, options, attributes=None): """ Writes an object to file. Writes the metadata for a Python object `data` to file at `name` in h5py.Group `grp`. Metadata is written to HDF5 Attributes. Existing Attributes that ...
python
def write_metadata(self, f, dsetgrp, data, type_string, options, attributes=None): """ Writes an object to file. Writes the metadata for a Python object `data` to file at `name` in h5py.Group `grp`. Metadata is written to HDF5 Attributes. Existing Attributes that ...
[ "def", "write_metadata", "(", "self", ",", "f", ",", "dsetgrp", ",", "data", ",", "type_string", ",", "options", ",", "attributes", "=", "None", ")", ":", "if", "attributes", "is", "None", ":", "attributes", "=", "dict", "(", ")", "# Make sure we have a co...
Writes an object to file. Writes the metadata for a Python object `data` to file at `name` in h5py.Group `grp`. Metadata is written to HDF5 Attributes. Existing Attributes that are not being used are deleted. .. versionchanged:: 0.2 Arguements changed. Param...
[ "Writes", "an", "object", "to", "file", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/Marshallers.py#L350-L408
42,232
frejanordsiek/hdf5storage
hdf5storage/utilities.py
process_path
def process_path(pth): """ Processes paths. Processes the provided path and breaks it into it Group part (`groupname`) and target part (`targetname`). ``bytes`` paths are converted to ``str``. Separated paths are given as an iterable of ``str`` and ``bytes``. Each part of a separated path is escape...
python
def process_path(pth): """ Processes paths. Processes the provided path and breaks it into it Group part (`groupname`) and target part (`targetname`). ``bytes`` paths are converted to ``str``. Separated paths are given as an iterable of ``str`` and ``bytes``. Each part of a separated path is escape...
[ "def", "process_path", "(", "pth", ")", ":", "# Do conversions and possibly escapes.", "if", "isinstance", "(", "pth", ",", "bytes", ")", ":", "p", "=", "pth", ".", "decode", "(", "'utf-8'", ")", "elif", "(", "sys", ".", "hexversion", ">=", "0x03000000", "...
Processes paths. Processes the provided path and breaks it into it Group part (`groupname`) and target part (`targetname`). ``bytes`` paths are converted to ``str``. Separated paths are given as an iterable of ``str`` and ``bytes``. Each part of a separated path is escaped using ``escape_path``. Ot...
[ "Processes", "paths", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L245-L339
42,233
frejanordsiek/hdf5storage
hdf5storage/utilities.py
write_object_array
def write_object_array(f, data, options): """ Writes an array of objects recursively. Writes the elements of the given object array recursively in the HDF5 Group ``options.group_for_references`` and returns an ``h5py.Reference`` array to all the elements. Parameters ---------- f : h5py.Fil...
python
def write_object_array(f, data, options): """ Writes an array of objects recursively. Writes the elements of the given object array recursively in the HDF5 Group ``options.group_for_references`` and returns an ``h5py.Reference`` array to all the elements. Parameters ---------- f : h5py.Fil...
[ "def", "write_object_array", "(", "f", ",", "data", ",", "options", ")", ":", "# We need to grab the special reference dtype and make an empty", "# array to store all the references in.", "ref_dtype", "=", "h5py", ".", "special_dtype", "(", "ref", "=", "h5py", ".", "Refer...
Writes an array of objects recursively. Writes the elements of the given object array recursively in the HDF5 Group ``options.group_for_references`` and returns an ``h5py.Reference`` array to all the elements. Parameters ---------- f : h5py.File The HDF5 file handle that is open. d...
[ "Writes", "an", "array", "of", "objects", "recursively", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L548-L654
42,234
frejanordsiek/hdf5storage
hdf5storage/utilities.py
read_object_array
def read_object_array(f, data, options): """ Reads an array of objects recursively. Read the elements of the given HDF5 Reference array recursively in the and constructs a ``numpy.object_`` array from its elements, which is returned. Parameters ---------- f : h5py.File The HDF5 fil...
python
def read_object_array(f, data, options): """ Reads an array of objects recursively. Read the elements of the given HDF5 Reference array recursively in the and constructs a ``numpy.object_`` array from its elements, which is returned. Parameters ---------- f : h5py.File The HDF5 fil...
[ "def", "read_object_array", "(", "f", ",", "data", ",", "options", ")", ":", "# Go through all the elements of data and read them using their", "# references, and the putting the output in new object array.", "data_derefed", "=", "np", ".", "zeros", "(", "shape", "=", "data",...
Reads an array of objects recursively. Read the elements of the given HDF5 Reference array recursively in the and constructs a ``numpy.object_`` array from its elements, which is returned. Parameters ---------- f : h5py.File The HDF5 file handle that is open. data : numpy.ndarray o...
[ "Reads", "an", "array", "of", "objects", "recursively", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L657-L699
42,235
frejanordsiek/hdf5storage
hdf5storage/utilities.py
next_unused_name_in_group
def next_unused_name_in_group(grp, length): """ Gives a name that isn't used in a Group. Generates a name of the desired length that is not a Dataset or Group in the given group. Note, if length is not large enough and `grp` is full enough, there may be no available names meaning that this function...
python
def next_unused_name_in_group(grp, length): """ Gives a name that isn't used in a Group. Generates a name of the desired length that is not a Dataset or Group in the given group. Note, if length is not large enough and `grp` is full enough, there may be no available names meaning that this function...
[ "def", "next_unused_name_in_group", "(", "grp", ",", "length", ")", ":", "# While", "#", "# ltrs = string.ascii_letters + string.digits", "# name = ''.join([random.choice(ltrs) for i in range(length)])", "#", "# seems intuitive, its performance is abysmal compared to", "#", "# '%0{0}x'...
Gives a name that isn't used in a Group. Generates a name of the desired length that is not a Dataset or Group in the given group. Note, if length is not large enough and `grp` is full enough, there may be no available names meaning that this function will hang. Parameters ---------- grp :...
[ "Gives", "a", "name", "that", "isn", "t", "used", "in", "a", "Group", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L702-L743
42,236
frejanordsiek/hdf5storage
hdf5storage/utilities.py
convert_numpy_str_to_uint16
def convert_numpy_str_to_uint16(data): """ Converts a numpy.unicode\_ to UTF-16 in numpy.uint16 form. Convert a ``numpy.unicode_`` or an array of them (they are UTF-32 strings) to UTF-16 in the equivalent array of ``numpy.uint16``. The conversion will throw an exception if any characters cannot be ...
python
def convert_numpy_str_to_uint16(data): """ Converts a numpy.unicode\_ to UTF-16 in numpy.uint16 form. Convert a ``numpy.unicode_`` or an array of them (they are UTF-32 strings) to UTF-16 in the equivalent array of ``numpy.uint16``. The conversion will throw an exception if any characters cannot be ...
[ "def", "convert_numpy_str_to_uint16", "(", "data", ")", ":", "# An empty string should be an empty uint16", "if", "data", ".", "nbytes", "==", "0", ":", "return", "np", ".", "uint16", "(", "[", "]", ")", "# We need to use the UTF-16 codec for our endianness. Using the", ...
Converts a numpy.unicode\_ to UTF-16 in numpy.uint16 form. Convert a ``numpy.unicode_`` or an array of them (they are UTF-32 strings) to UTF-16 in the equivalent array of ``numpy.uint16``. The conversion will throw an exception if any characters cannot be converted to UTF-16. Strings are expanded along...
[ "Converts", "a", "numpy", ".", "unicode", "\\", "_", "to", "UTF", "-", "16", "in", "numpy", ".", "uint16", "form", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L745-L797
42,237
frejanordsiek/hdf5storage
hdf5storage/utilities.py
convert_numpy_str_to_uint32
def convert_numpy_str_to_uint32(data): """ Converts a numpy.unicode\_ to its numpy.uint32 representation. Convert a ``numpy.unicode_`` or an array of them (they are UTF-32 strings) into the equivalent array of ``numpy.uint32`` that is byte for byte identical. Strings are expanded along rows (across col...
python
def convert_numpy_str_to_uint32(data): """ Converts a numpy.unicode\_ to its numpy.uint32 representation. Convert a ``numpy.unicode_`` or an array of them (they are UTF-32 strings) into the equivalent array of ``numpy.uint32`` that is byte for byte identical. Strings are expanded along rows (across col...
[ "def", "convert_numpy_str_to_uint32", "(", "data", ")", ":", "if", "data", ".", "nbytes", "==", "0", ":", "# An empty string should be an empty uint32.", "return", "np", ".", "uint32", "(", "[", "]", ")", "else", ":", "# We need to calculate the new shape from the cur...
Converts a numpy.unicode\_ to its numpy.uint32 representation. Convert a ``numpy.unicode_`` or an array of them (they are UTF-32 strings) into the equivalent array of ``numpy.uint32`` that is byte for byte identical. Strings are expanded along rows (across columns) so a 2x3x4 array of 10 element string...
[ "Converts", "a", "numpy", ".", "unicode", "\\", "_", "to", "its", "numpy", ".", "uint32", "representation", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L800-L838
42,238
frejanordsiek/hdf5storage
hdf5storage/utilities.py
decode_complex
def decode_complex(data, complex_names=(None, None)): """ Decodes possibly complex data read from an HDF5 file. Decodes possibly complex datasets read from an HDF5 file. HDF5 doesn't have a native complex type, so they are stored as H5T_COMPOUND types with fields such as 'r' and 'i' for the real and ...
python
def decode_complex(data, complex_names=(None, None)): """ Decodes possibly complex data read from an HDF5 file. Decodes possibly complex datasets read from an HDF5 file. HDF5 doesn't have a native complex type, so they are stored as H5T_COMPOUND types with fields such as 'r' and 'i' for the real and ...
[ "def", "decode_complex", "(", "data", ",", "complex_names", "=", "(", "None", ",", "None", ")", ")", ":", "# Now, complex types are stored in HDF5 files as an H5T_COMPOUND type", "# with fields along the lines of ('r', 're', 'real') and ('i', 'im',", "# 'imag', 'imaginary') for the r...
Decodes possibly complex data read from an HDF5 file. Decodes possibly complex datasets read from an HDF5 file. HDF5 doesn't have a native complex type, so they are stored as H5T_COMPOUND types with fields such as 'r' and 'i' for the real and imaginary parts. As there is no standardization for field na...
[ "Decodes", "possibly", "complex", "data", "read", "from", "an", "HDF5", "file", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1177-L1262
42,239
frejanordsiek/hdf5storage
hdf5storage/utilities.py
encode_complex
def encode_complex(data, complex_names): """ Encodes complex data to having arbitrary complex field names. Encodes complex `data` to have the real and imaginary field names given in `complex_numbers`. This is needed because the field names have to be set so that it can be written to an HDF5 file with t...
python
def encode_complex(data, complex_names): """ Encodes complex data to having arbitrary complex field names. Encodes complex `data` to have the real and imaginary field names given in `complex_numbers`. This is needed because the field names have to be set so that it can be written to an HDF5 file with t...
[ "def", "encode_complex", "(", "data", ",", "complex_names", ")", ":", "# Grab the dtype name, and convert it to the right non-complex type", "# if it isn't already one.", "dtype_name", "=", "data", ".", "dtype", ".", "name", "if", "dtype_name", "[", "0", ":", "7", "]", ...
Encodes complex data to having arbitrary complex field names. Encodes complex `data` to have the real and imaginary field names given in `complex_numbers`. This is needed because the field names have to be set so that it can be written to an HDF5 file with the right field names (HDF5 doesn't have a nat...
[ "Encodes", "complex", "data", "to", "having", "arbitrary", "complex", "field", "names", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1265-L1305
42,240
frejanordsiek/hdf5storage
hdf5storage/utilities.py
convert_attribute_to_string
def convert_attribute_to_string(value): """ Convert an attribute value to a string. Converts the attribute value to a string if possible (get ``None`` if isn't a string type). .. versionadded:: 0.2 Parameters ---------- value : The Attribute value. Returns ------- s :...
python
def convert_attribute_to_string(value): """ Convert an attribute value to a string. Converts the attribute value to a string if possible (get ``None`` if isn't a string type). .. versionadded:: 0.2 Parameters ---------- value : The Attribute value. Returns ------- s :...
[ "def", "convert_attribute_to_string", "(", "value", ")", ":", "if", "value", "is", "None", ":", "return", "value", "elif", "(", "sys", ".", "hexversion", ">=", "0x03000000", "and", "isinstance", "(", "value", ",", "str", ")", ")", "or", "(", "sys", ".", ...
Convert an attribute value to a string. Converts the attribute value to a string if possible (get ``None`` if isn't a string type). .. versionadded:: 0.2 Parameters ---------- value : The Attribute value. Returns ------- s : str or None The ``str`` value of the at...
[ "Convert", "an", "attribute", "value", "to", "a", "string", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1334-L1367
42,241
frejanordsiek/hdf5storage
hdf5storage/utilities.py
set_attribute
def set_attribute(target, name, value): """ Sets an attribute on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten if it differs from `value`. Notes ----- ``set_attributes_all`` is the fastest way to set and delete Attribu...
python
def set_attribute(target, name, value): """ Sets an attribute on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten if it differs from `value`. Notes ----- ``set_attributes_all`` is the fastest way to set and delete Attribu...
[ "def", "set_attribute", "(", "target", ",", "name", ",", "value", ")", ":", "try", ":", "target", ".", "attrs", ".", "modify", "(", "name", ",", "value", ")", "except", ":", "target", ".", "attrs", ".", "create", "(", "name", ",", "value", ")" ]
Sets an attribute on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten if it differs from `value`. Notes ----- ``set_attributes_all`` is the fastest way to set and delete Attributes in bulk. Parameters ---------- ...
[ "Sets", "an", "attribute", "on", "a", "Dataset", "or", "Group", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1442-L1470
42,242
frejanordsiek/hdf5storage
hdf5storage/utilities.py
set_attribute_string
def set_attribute_string(target, name, value): """ Sets an attribute to a string on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten if it differs from `value`. Notes ----- ``set_attributes_all`` is the fastest way to set and...
python
def set_attribute_string(target, name, value): """ Sets an attribute to a string on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten if it differs from `value`. Notes ----- ``set_attributes_all`` is the fastest way to set and...
[ "def", "set_attribute_string", "(", "target", ",", "name", ",", "value", ")", ":", "set_attribute", "(", "target", ",", "name", ",", "np", ".", "bytes_", "(", "value", ")", ")" ]
Sets an attribute to a string on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten if it differs from `value`. Notes ----- ``set_attributes_all`` is the fastest way to set and delete Attributes in bulk. Parameters ---...
[ "Sets", "an", "attribute", "to", "a", "string", "on", "a", "Dataset", "or", "Group", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1473-L1499
42,243
frejanordsiek/hdf5storage
hdf5storage/utilities.py
set_attribute_string_array
def set_attribute_string_array(target, name, string_list): """ Sets an attribute to an array of string on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten with the list of string `string_list` (they will be vlen strings). Notes ...
python
def set_attribute_string_array(target, name, string_list): """ Sets an attribute to an array of string on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten with the list of string `string_list` (they will be vlen strings). Notes ...
[ "def", "set_attribute_string_array", "(", "target", ",", "name", ",", "string_list", ")", ":", "s_list", "=", "[", "convert_to_str", "(", "s", ")", "for", "s", "in", "string_list", "]", "if", "sys", ".", "hexversion", ">=", "0x03000000", ":", "target", "."...
Sets an attribute to an array of string on a Dataset or Group. If the attribute `name` doesn't exist yet, it is created. If it already exists, it is overwritten with the list of string `string_list` (they will be vlen strings). Notes ----- ``set_attributes_all`` is the fastest way to set and d...
[ "Sets", "an", "attribute", "to", "an", "array", "of", "string", "on", "a", "Dataset", "or", "Group", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1502-L1534
42,244
frejanordsiek/hdf5storage
hdf5storage/utilities.py
set_attributes_all
def set_attributes_all(target, attributes, discard_others=True): """ Set Attributes in bulk and optionally discard others. Sets each Attribute in turn (modifying it in place if possible if it is already present) and optionally discarding all other Attributes not explicitly set. This function yields muc...
python
def set_attributes_all(target, attributes, discard_others=True): """ Set Attributes in bulk and optionally discard others. Sets each Attribute in turn (modifying it in place if possible if it is already present) and optionally discarding all other Attributes not explicitly set. This function yields muc...
[ "def", "set_attributes_all", "(", "target", ",", "attributes", ",", "discard_others", "=", "True", ")", ":", "attrs", "=", "target", ".", "attrs", "existing", "=", "dict", "(", "attrs", ".", "items", "(", ")", ")", "# Generate special dtype for string arrays.", ...
Set Attributes in bulk and optionally discard others. Sets each Attribute in turn (modifying it in place if possible if it is already present) and optionally discarding all other Attributes not explicitly set. This function yields much greater performance than the required individual calls to ``set_att...
[ "Set", "Attributes", "in", "bulk", "and", "optionally", "discard", "others", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/utilities.py#L1537-L1599
42,245
frejanordsiek/hdf5storage
hdf5storage/__init__.py
find_thirdparty_marshaller_plugins
def find_thirdparty_marshaller_plugins(): """ Find, but don't load, all third party marshaller plugins. Third party marshaller plugins declare the entry point ``'hdf5storage.marshallers.plugins'`` with the name being the Marshaller API version and the target being a function that returns a ``tuple`...
python
def find_thirdparty_marshaller_plugins(): """ Find, but don't load, all third party marshaller plugins. Third party marshaller plugins declare the entry point ``'hdf5storage.marshallers.plugins'`` with the name being the Marshaller API version and the target being a function that returns a ``tuple`...
[ "def", "find_thirdparty_marshaller_plugins", "(", ")", ":", "all_plugins", "=", "tuple", "(", "pkg_resources", ".", "iter_entry_points", "(", "'hdf5storage.marshallers.plugins'", ")", ")", "return", "{", "ver", ":", "{", "p", ".", "module_name", ":", "p", "for", ...
Find, but don't load, all third party marshaller plugins. Third party marshaller plugins declare the entry point ``'hdf5storage.marshallers.plugins'`` with the name being the Marshaller API version and the target being a function that returns a ``tuple`` or ``list`` of all the marshallers provided by t...
[ "Find", "but", "don", "t", "load", "all", "third", "party", "marshaller", "plugins", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L85-L115
42,246
frejanordsiek/hdf5storage
hdf5storage/__init__.py
savemat
def savemat(file_name, mdict, appendmat=True, format='7.3', oned_as='row', store_python_metadata=True, action_for_matlab_incompatible='error', marshaller_collection=None, truncate_existing=False, truncate_invalid_matlab=False, **keywords): """ Save a dictionary of pyt...
python
def savemat(file_name, mdict, appendmat=True, format='7.3', oned_as='row', store_python_metadata=True, action_for_matlab_incompatible='error', marshaller_collection=None, truncate_existing=False, truncate_invalid_matlab=False, **keywords): """ Save a dictionary of pyt...
[ "def", "savemat", "(", "file_name", ",", "mdict", ",", "appendmat", "=", "True", ",", "format", "=", "'7.3'", ",", "oned_as", "=", "'row'", ",", "store_python_metadata", "=", "True", ",", "action_for_matlab_incompatible", "=", "'error'", ",", "marshaller_collect...
Save a dictionary of python types to a MATLAB MAT file. Saves the data provided in the dictionary `mdict` to a MATLAB MAT file. `format` determines which kind/vesion of file to use. The '7.3' version, which is HDF5 based, is handled by this package and all types that this package can write are supporte...
[ "Save", "a", "dictionary", "of", "python", "types", "to", "a", "MATLAB", "MAT", "file", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1855-L1964
42,247
frejanordsiek/hdf5storage
hdf5storage/__init__.py
loadmat
def loadmat(file_name, mdict=None, appendmat=True, variable_names=None, marshaller_collection=None, **keywords): """ Loads data to a MATLAB MAT file. Reads data from the specified variables (or all) in a MATLAB MAT file. There are many different formats of MAT files. This package ...
python
def loadmat(file_name, mdict=None, appendmat=True, variable_names=None, marshaller_collection=None, **keywords): """ Loads data to a MATLAB MAT file. Reads data from the specified variables (or all) in a MATLAB MAT file. There are many different formats of MAT files. This package ...
[ "def", "loadmat", "(", "file_name", ",", "mdict", "=", "None", ",", "appendmat", "=", "True", ",", "variable_names", "=", "None", ",", "marshaller_collection", "=", "None", ",", "*", "*", "keywords", ")", ":", "# Will first assume that it is the HDF5 based 7.3 for...
Loads data to a MATLAB MAT file. Reads data from the specified variables (or all) in a MATLAB MAT file. There are many different formats of MAT files. This package can only handle the HDF5 based ones (the version 7.3 and later). As SciPy's ``scipy.io.loadmat`` function can handle the earlier forma...
[ "Loads", "data", "to", "a", "MATLAB", "MAT", "file", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1967-L2084
42,248
frejanordsiek/hdf5storage
hdf5storage/__init__.py
MarshallerCollection._update_marshallers
def _update_marshallers(self): """ Update the full marshaller list and other data structures. Makes a full list of both builtin and user marshallers and rebuilds internal data structures used for looking up which marshaller to use for reading/writing Python objects to/from file....
python
def _update_marshallers(self): """ Update the full marshaller list and other data structures. Makes a full list of both builtin and user marshallers and rebuilds internal data structures used for looking up which marshaller to use for reading/writing Python objects to/from file....
[ "def", "_update_marshallers", "(", "self", ")", ":", "# Combine all sets of marshallers.", "self", ".", "_marshallers", "=", "[", "]", "for", "v", "in", "self", ".", "_priority", ":", "if", "v", "==", "'builtin'", ":", "self", ".", "_marshallers", ".", "exte...
Update the full marshaller list and other data structures. Makes a full list of both builtin and user marshallers and rebuilds internal data structures used for looking up which marshaller to use for reading/writing Python objects to/from file. Also checks for whether the requi...
[ "Update", "the", "full", "marshaller", "list", "and", "other", "data", "structures", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1173-L1277
42,249
frejanordsiek/hdf5storage
hdf5storage/__init__.py
MarshallerCollection._import_marshaller_modules
def _import_marshaller_modules(self, m): """ Imports the modules required by the marshaller. Parameters ---------- m : marshaller The marshaller to load the modules for. Returns ------- success : bool Whether the modules `m` requires coul...
python
def _import_marshaller_modules(self, m): """ Imports the modules required by the marshaller. Parameters ---------- m : marshaller The marshaller to load the modules for. Returns ------- success : bool Whether the modules `m` requires coul...
[ "def", "_import_marshaller_modules", "(", "self", ",", "m", ")", ":", "try", ":", "for", "name", "in", "m", ".", "required_modules", ":", "if", "name", "not", "in", "sys", ".", "modules", ":", "if", "_has_importlib", ":", "importlib", ".", "import_module",...
Imports the modules required by the marshaller. Parameters ---------- m : marshaller The marshaller to load the modules for. Returns ------- success : bool Whether the modules `m` requires could be imported successfully or not.
[ "Imports", "the", "modules", "required", "by", "the", "marshaller", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1279-L1306
42,250
frejanordsiek/hdf5storage
hdf5storage/__init__.py
MarshallerCollection.get_marshaller_for_type
def get_marshaller_for_type(self, tp): """ Gets the appropriate marshaller for a type. Retrieves the marshaller, if any, that can be used to read/write a Python object with type 'tp'. The modules it requires, if available, will be loaded. Parameters ---------- t...
python
def get_marshaller_for_type(self, tp): """ Gets the appropriate marshaller for a type. Retrieves the marshaller, if any, that can be used to read/write a Python object with type 'tp'. The modules it requires, if available, will be loaded. Parameters ---------- t...
[ "def", "get_marshaller_for_type", "(", "self", ",", "tp", ")", ":", "if", "not", "isinstance", "(", "tp", ",", "str", ")", ":", "tp", "=", "tp", ".", "__module__", "+", "'.'", "+", "tp", ".", "__name__", "if", "tp", "in", "self", ".", "_types", ":"...
Gets the appropriate marshaller for a type. Retrieves the marshaller, if any, that can be used to read/write a Python object with type 'tp'. The modules it requires, if available, will be loaded. Parameters ---------- tp : type or str Python object ``type`` ...
[ "Gets", "the", "appropriate", "marshaller", "for", "a", "type", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1382-L1423
42,251
frejanordsiek/hdf5storage
hdf5storage/__init__.py
MarshallerCollection.get_marshaller_for_type_string
def get_marshaller_for_type_string(self, type_string): """ Gets the appropriate marshaller for a type string. Retrieves the marshaller, if any, that can be used to read/write a Python object with the given type string. The modules it requires, if available, will be loaded. Para...
python
def get_marshaller_for_type_string(self, type_string): """ Gets the appropriate marshaller for a type string. Retrieves the marshaller, if any, that can be used to read/write a Python object with the given type string. The modules it requires, if available, will be loaded. Para...
[ "def", "get_marshaller_for_type_string", "(", "self", ",", "type_string", ")", ":", "if", "type_string", "in", "self", ".", "_type_strings", ":", "index", "=", "self", ".", "_type_strings", "[", "type_string", "]", "m", "=", "self", ".", "_marshallers", "[", ...
Gets the appropriate marshaller for a type string. Retrieves the marshaller, if any, that can be used to read/write a Python object with the given type string. The modules it requires, if available, will be loaded. Parameters ---------- type_string : str Typ...
[ "Gets", "the", "appropriate", "marshaller", "for", "a", "type", "string", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1425-L1463
42,252
frejanordsiek/hdf5storage
hdf5storage/__init__.py
MarshallerCollection.get_marshaller_for_matlab_class
def get_marshaller_for_matlab_class(self, matlab_class): """ Gets the appropriate marshaller for a MATLAB class string. Retrieves the marshaller, if any, that can be used to read/write a Python object associated with the given MATLAB class string. The modules it requires, if available, ...
python
def get_marshaller_for_matlab_class(self, matlab_class): """ Gets the appropriate marshaller for a MATLAB class string. Retrieves the marshaller, if any, that can be used to read/write a Python object associated with the given MATLAB class string. The modules it requires, if available, ...
[ "def", "get_marshaller_for_matlab_class", "(", "self", ",", "matlab_class", ")", ":", "if", "matlab_class", "in", "self", ".", "_matlab_classes", ":", "index", "=", "self", ".", "_matlab_classes", "[", "matlab_class", "]", "m", "=", "self", ".", "_marshallers", ...
Gets the appropriate marshaller for a MATLAB class string. Retrieves the marshaller, if any, that can be used to read/write a Python object associated with the given MATLAB class string. The modules it requires, if available, will be loaded. Parameters ---------- matlab...
[ "Gets", "the", "appropriate", "marshaller", "for", "a", "MATLAB", "class", "string", "." ]
539275141dd3a4efbbbfd9bdb978f3ed59e3f05d
https://github.com/frejanordsiek/hdf5storage/blob/539275141dd3a4efbbbfd9bdb978f3ed59e3f05d/hdf5storage/__init__.py#L1465-L1503
42,253
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.new_node
def new_node(self): """Adds a new, blank node to the graph. Returns the node id of the new node.""" node_id = self.generate_node_id() node = {'id': node_id, 'edges': [], 'data': {} } self.nodes[node_id] = node self._num_nodes += ...
python
def new_node(self): """Adds a new, blank node to the graph. Returns the node id of the new node.""" node_id = self.generate_node_id() node = {'id': node_id, 'edges': [], 'data': {} } self.nodes[node_id] = node self._num_nodes += ...
[ "def", "new_node", "(", "self", ")", ":", "node_id", "=", "self", ".", "generate_node_id", "(", ")", "node", "=", "{", "'id'", ":", "node_id", ",", "'edges'", ":", "[", "]", ",", "'data'", ":", "{", "}", "}", "self", ".", "nodes", "[", "node_id", ...
Adds a new, blank node to the graph. Returns the node id of the new node.
[ "Adds", "a", "new", "blank", "node", "to", "the", "graph", ".", "Returns", "the", "node", "id", "of", "the", "new", "node", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L48-L62
42,254
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.new_edge
def new_edge(self, node_a, node_b, cost=1): """Adds a new edge from node_a to node_b that has a cost. Returns the edge id of the new edge.""" # Verify that both nodes exist in the graph try: self.nodes[node_a] except KeyError: raise NonexistentNodeError(n...
python
def new_edge(self, node_a, node_b, cost=1): """Adds a new edge from node_a to node_b that has a cost. Returns the edge id of the new edge.""" # Verify that both nodes exist in the graph try: self.nodes[node_a] except KeyError: raise NonexistentNodeError(n...
[ "def", "new_edge", "(", "self", ",", "node_a", ",", "node_b", ",", "cost", "=", "1", ")", ":", "# Verify that both nodes exist in the graph", "try", ":", "self", ".", "nodes", "[", "node_a", "]", "except", "KeyError", ":", "raise", "NonexistentNodeError", "(",...
Adds a new edge from node_a to node_b that has a cost. Returns the edge id of the new edge.
[ "Adds", "a", "new", "edge", "from", "node_a", "to", "node_b", "that", "has", "a", "cost", ".", "Returns", "the", "edge", "id", "of", "the", "new", "edge", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L64-L92
42,255
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.adjacent
def adjacent(self, node_a, node_b): """Determines whether there is an edge from node_a to node_b. Returns True if such an edge exists, otherwise returns False.""" neighbors = self.neighbors(node_a) return node_b in neighbors
python
def adjacent(self, node_a, node_b): """Determines whether there is an edge from node_a to node_b. Returns True if such an edge exists, otherwise returns False.""" neighbors = self.neighbors(node_a) return node_b in neighbors
[ "def", "adjacent", "(", "self", ",", "node_a", ",", "node_b", ")", ":", "neighbors", "=", "self", ".", "neighbors", "(", "node_a", ")", "return", "node_b", "in", "neighbors" ]
Determines whether there is an edge from node_a to node_b. Returns True if such an edge exists, otherwise returns False.
[ "Determines", "whether", "there", "is", "an", "edge", "from", "node_a", "to", "node_b", ".", "Returns", "True", "if", "such", "an", "edge", "exists", "otherwise", "returns", "False", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L100-L104
42,256
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.edge_cost
def edge_cost(self, node_a, node_b): """Returns the cost of moving between the edge that connects node_a to node_b. Returns +inf if no such edge exists.""" cost = float('inf') node_object_a = self.get_node(node_a) for edge_id in node_object_a['edges']: edge = self.get...
python
def edge_cost(self, node_a, node_b): """Returns the cost of moving between the edge that connects node_a to node_b. Returns +inf if no such edge exists.""" cost = float('inf') node_object_a = self.get_node(node_a) for edge_id in node_object_a['edges']: edge = self.get...
[ "def", "edge_cost", "(", "self", ",", "node_a", ",", "node_b", ")", ":", "cost", "=", "float", "(", "'inf'", ")", "node_object_a", "=", "self", ".", "get_node", "(", "node_a", ")", "for", "edge_id", "in", "node_object_a", "[", "'edges'", "]", ":", "edg...
Returns the cost of moving between the edge that connects node_a to node_b. Returns +inf if no such edge exists.
[ "Returns", "the", "cost", "of", "moving", "between", "the", "edge", "that", "connects", "node_a", "to", "node_b", ".", "Returns", "+", "inf", "if", "no", "such", "edge", "exists", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L106-L117
42,257
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.get_node
def get_node(self, node_id): """Returns the node object identified by "node_id".""" try: node_object = self.nodes[node_id] except KeyError: raise NonexistentNodeError(node_id) return node_object
python
def get_node(self, node_id): """Returns the node object identified by "node_id".""" try: node_object = self.nodes[node_id] except KeyError: raise NonexistentNodeError(node_id) return node_object
[ "def", "get_node", "(", "self", ",", "node_id", ")", ":", "try", ":", "node_object", "=", "self", ".", "nodes", "[", "node_id", "]", "except", "KeyError", ":", "raise", "NonexistentNodeError", "(", "node_id", ")", "return", "node_object" ]
Returns the node object identified by "node_id".
[ "Returns", "the", "node", "object", "identified", "by", "node_id", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L119-L125
42,258
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.get_edge
def get_edge(self, edge_id): """Returns the edge object identified by "edge_id".""" try: edge_object = self.edges[edge_id] except KeyError: raise NonexistentEdgeError(edge_id) return edge_object
python
def get_edge(self, edge_id): """Returns the edge object identified by "edge_id".""" try: edge_object = self.edges[edge_id] except KeyError: raise NonexistentEdgeError(edge_id) return edge_object
[ "def", "get_edge", "(", "self", ",", "edge_id", ")", ":", "try", ":", "edge_object", "=", "self", ".", "edges", "[", "edge_id", "]", "except", "KeyError", ":", "raise", "NonexistentEdgeError", "(", "edge_id", ")", "return", "edge_object" ]
Returns the edge object identified by "edge_id".
[ "Returns", "the", "edge", "object", "identified", "by", "edge_id", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L135-L141
42,259
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.delete_edge_by_nodes
def delete_edge_by_nodes(self, node_a, node_b): """Removes all the edges from node_a to node_b from the graph.""" node = self.get_node(node_a) # Determine the edge ids edge_ids = [] for e_id in node['edges']: edge = self.get_edge(e_id) if edge['vertices']...
python
def delete_edge_by_nodes(self, node_a, node_b): """Removes all the edges from node_a to node_b from the graph.""" node = self.get_node(node_a) # Determine the edge ids edge_ids = [] for e_id in node['edges']: edge = self.get_edge(e_id) if edge['vertices']...
[ "def", "delete_edge_by_nodes", "(", "self", ",", "node_a", ",", "node_b", ")", ":", "node", "=", "self", ".", "get_node", "(", "node_a", ")", "# Determine the edge ids", "edge_ids", "=", "[", "]", "for", "e_id", "in", "node", "[", "'edges'", "]", ":", "e...
Removes all the edges from node_a to node_b from the graph.
[ "Removes", "all", "the", "edges", "from", "node_a", "to", "node_b", "from", "the", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L168-L181
42,260
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.delete_node
def delete_node(self, node_id): """Removes the node identified by node_id from the graph.""" node = self.get_node(node_id) # Remove all edges from the node for e in node['edges']: self.delete_edge_by_id(e) # Remove all edges to the node edges = [edge_id for ...
python
def delete_node(self, node_id): """Removes the node identified by node_id from the graph.""" node = self.get_node(node_id) # Remove all edges from the node for e in node['edges']: self.delete_edge_by_id(e) # Remove all edges to the node edges = [edge_id for ...
[ "def", "delete_node", "(", "self", ",", "node_id", ")", ":", "node", "=", "self", ".", "get_node", "(", "node_id", ")", "# Remove all edges from the node", "for", "e", "in", "node", "[", "'edges'", "]", ":", "self", ".", "delete_edge_by_id", "(", "e", ")",...
Removes the node identified by node_id from the graph.
[ "Removes", "the", "node", "identified", "by", "node_id", "from", "the", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L183-L199
42,261
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.move_edge_source
def move_edge_source(self, edge_id, node_a, node_b): """Moves an edge originating from node_a so that it originates from node_b.""" # Grab the edge edge = self.get_edge(edge_id) # Alter the vertices edge['vertices'] = (node_b, edge['vertices'][1]) # Remove the edge from...
python
def move_edge_source(self, edge_id, node_a, node_b): """Moves an edge originating from node_a so that it originates from node_b.""" # Grab the edge edge = self.get_edge(edge_id) # Alter the vertices edge['vertices'] = (node_b, edge['vertices'][1]) # Remove the edge from...
[ "def", "move_edge_source", "(", "self", ",", "edge_id", ",", "node_a", ",", "node_b", ")", ":", "# Grab the edge", "edge", "=", "self", ".", "get_edge", "(", "edge_id", ")", "# Alter the vertices", "edge", "[", "'vertices'", "]", "=", "(", "node_b", ",", "...
Moves an edge originating from node_a so that it originates from node_b.
[ "Moves", "an", "edge", "originating", "from", "node_a", "so", "that", "it", "originates", "from", "node_b", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L201-L215
42,262
jciskey/pygraph
pygraph/classes/directed_graph.py
DirectedGraph.get_edge_ids_by_node_ids
def get_edge_ids_by_node_ids(self, node_a, node_b): """Returns a list of edge ids connecting node_a to node_b.""" # Check if the nodes are adjacent if not self.adjacent(node_a, node_b): return [] # They're adjacent, so pull the list of edges from node_a and determine which o...
python
def get_edge_ids_by_node_ids(self, node_a, node_b): """Returns a list of edge ids connecting node_a to node_b.""" # Check if the nodes are adjacent if not self.adjacent(node_a, node_b): return [] # They're adjacent, so pull the list of edges from node_a and determine which o...
[ "def", "get_edge_ids_by_node_ids", "(", "self", ",", "node_a", ",", "node_b", ")", ":", "# Check if the nodes are adjacent", "if", "not", "self", ".", "adjacent", "(", "node_a", ",", "node_b", ")", ":", "return", "[", "]", "# They're adjacent, so pull the list of ed...
Returns a list of edge ids connecting node_a to node_b.
[ "Returns", "a", "list", "of", "edge", "ids", "connecting", "node_a", "to", "node_b", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/directed_graph.py#L225-L233
42,263
jciskey/pygraph
pygraph/functions/biconnected_components.py
find_biconnected_components
def find_biconnected_components(graph): """Finds all the biconnected components in a graph. Returns a list of lists, each containing the edges that form a biconnected component. Returns an empty list for an empty graph. """ list_of_components = [] # Run the algorithm on each of the connected c...
python
def find_biconnected_components(graph): """Finds all the biconnected components in a graph. Returns a list of lists, each containing the edges that form a biconnected component. Returns an empty list for an empty graph. """ list_of_components = [] # Run the algorithm on each of the connected c...
[ "def", "find_biconnected_components", "(", "graph", ")", ":", "list_of_components", "=", "[", "]", "# Run the algorithm on each of the connected components of the graph", "components", "=", "get_connected_components_as_subgraphs", "(", "graph", ")", "for", "component", "in", ...
Finds all the biconnected components in a graph. Returns a list of lists, each containing the edges that form a biconnected component. Returns an empty list for an empty graph.
[ "Finds", "all", "the", "biconnected", "components", "in", "a", "graph", ".", "Returns", "a", "list", "of", "lists", "each", "containing", "the", "edges", "that", "form", "a", "biconnected", "component", ".", "Returns", "an", "empty", "list", "for", "an", "...
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/biconnected_components.py#L9-L25
42,264
jciskey/pygraph
pygraph/functions/biconnected_components.py
find_biconnected_components_as_subgraphs
def find_biconnected_components_as_subgraphs(graph): """Finds the biconnected components and returns them as subgraphs.""" list_of_graphs = [] list_of_components = find_biconnected_components(graph) for edge_list in list_of_components: subgraph = get_subgraph_from_edge_list(graph, edge_list) ...
python
def find_biconnected_components_as_subgraphs(graph): """Finds the biconnected components and returns them as subgraphs.""" list_of_graphs = [] list_of_components = find_biconnected_components(graph) for edge_list in list_of_components: subgraph = get_subgraph_from_edge_list(graph, edge_list) ...
[ "def", "find_biconnected_components_as_subgraphs", "(", "graph", ")", ":", "list_of_graphs", "=", "[", "]", "list_of_components", "=", "find_biconnected_components", "(", "graph", ")", "for", "edge_list", "in", "list_of_components", ":", "subgraph", "=", "get_subgraph_f...
Finds the biconnected components and returns them as subgraphs.
[ "Finds", "the", "biconnected", "components", "and", "returns", "them", "as", "subgraphs", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/biconnected_components.py#L28-L37
42,265
jciskey/pygraph
pygraph/functions/biconnected_components.py
find_articulation_vertices
def find_articulation_vertices(graph): """Finds all of the articulation vertices within a graph. Returns a list of all articulation vertices within the graph. Returns an empty list for an empty graph. """ articulation_vertices = [] all_nodes = graph.get_all_node_ids() if len(all_nodes) == ...
python
def find_articulation_vertices(graph): """Finds all of the articulation vertices within a graph. Returns a list of all articulation vertices within the graph. Returns an empty list for an empty graph. """ articulation_vertices = [] all_nodes = graph.get_all_node_ids() if len(all_nodes) == ...
[ "def", "find_articulation_vertices", "(", "graph", ")", ":", "articulation_vertices", "=", "[", "]", "all_nodes", "=", "graph", ".", "get_all_node_ids", "(", ")", "if", "len", "(", "all_nodes", ")", "==", "0", ":", "return", "articulation_vertices", "# Run the a...
Finds all of the articulation vertices within a graph. Returns a list of all articulation vertices within the graph. Returns an empty list for an empty graph.
[ "Finds", "all", "of", "the", "articulation", "vertices", "within", "a", "graph", ".", "Returns", "a", "list", "of", "all", "articulation", "vertices", "within", "the", "graph", ".", "Returns", "an", "empty", "list", "for", "an", "empty", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/biconnected_components.py#L40-L60
42,266
jciskey/pygraph
pygraph/functions/biconnected_components.py
output_component
def output_component(graph, edge_stack, u, v): """Helper function to pop edges off the stack and produce a list of them.""" edge_list = [] while len(edge_stack) > 0: edge_id = edge_stack.popleft() edge_list.append(edge_id) edge = graph.get_edge(edge_id) tpl_a = (u, v) ...
python
def output_component(graph, edge_stack, u, v): """Helper function to pop edges off the stack and produce a list of them.""" edge_list = [] while len(edge_stack) > 0: edge_id = edge_stack.popleft() edge_list.append(edge_id) edge = graph.get_edge(edge_id) tpl_a = (u, v) ...
[ "def", "output_component", "(", "graph", ",", "edge_stack", ",", "u", ",", "v", ")", ":", "edge_list", "=", "[", "]", "while", "len", "(", "edge_stack", ")", ">", "0", ":", "edge_id", "=", "edge_stack", ".", "popleft", "(", ")", "edge_list", ".", "ap...
Helper function to pop edges off the stack and produce a list of them.
[ "Helper", "function", "to", "pop", "edges", "off", "the", "stack", "and", "produce", "a", "list", "of", "them", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/biconnected_components.py#L179-L192
42,267
jciskey/pygraph
pygraph/functions/searching/depth_first_search.py
depth_first_search_with_parent_data
def depth_first_search_with_parent_data(graph, root_node = None, adjacency_lists = None): """Performs a depth-first search with visiting order of nodes determined by provided adjacency lists, and also returns a parent lookup dict and a children lookup dict.""" ordering = [] parent_lookup = {} child...
python
def depth_first_search_with_parent_data(graph, root_node = None, adjacency_lists = None): """Performs a depth-first search with visiting order of nodes determined by provided adjacency lists, and also returns a parent lookup dict and a children lookup dict.""" ordering = [] parent_lookup = {} child...
[ "def", "depth_first_search_with_parent_data", "(", "graph", ",", "root_node", "=", "None", ",", "adjacency_lists", "=", "None", ")", ":", "ordering", "=", "[", "]", "parent_lookup", "=", "{", "}", "children_lookup", "=", "defaultdict", "(", "lambda", ":", "[",...
Performs a depth-first search with visiting order of nodes determined by provided adjacency lists, and also returns a parent lookup dict and a children lookup dict.
[ "Performs", "a", "depth", "-", "first", "search", "with", "visiting", "order", "of", "nodes", "determined", "by", "provided", "adjacency", "lists", "and", "also", "returns", "a", "parent", "lookup", "dict", "and", "a", "children", "lookup", "dict", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/searching/depth_first_search.py#L15-L72
42,268
jciskey/pygraph
pygraph/render.py
graph_to_dot
def graph_to_dot(graph, node_renderer=None, edge_renderer=None): """Produces a DOT specification string from the provided graph.""" node_pairs = list(graph.nodes.items()) edge_pairs = list(graph.edges.items()) if node_renderer is None: node_renderer_wrapper = lambda nid: '' else: no...
python
def graph_to_dot(graph, node_renderer=None, edge_renderer=None): """Produces a DOT specification string from the provided graph.""" node_pairs = list(graph.nodes.items()) edge_pairs = list(graph.edges.items()) if node_renderer is None: node_renderer_wrapper = lambda nid: '' else: no...
[ "def", "graph_to_dot", "(", "graph", ",", "node_renderer", "=", "None", ",", "edge_renderer", "=", "None", ")", ":", "node_pairs", "=", "list", "(", "graph", ".", "nodes", ".", "items", "(", ")", ")", "edge_pairs", "=", "list", "(", "graph", ".", "edge...
Produces a DOT specification string from the provided graph.
[ "Produces", "a", "DOT", "specification", "string", "from", "the", "provided", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/render.py#L4-L32
42,269
jciskey/pygraph
pygraph/functions/connected_components.py
get_connected_components
def get_connected_components(graph): """Finds all connected components of the graph. Returns a list of lists, each containing the nodes that form a connected component. Returns an empty list for an empty graph. """ list_of_components = [] component = [] # Not strictly necessary due to the whil...
python
def get_connected_components(graph): """Finds all connected components of the graph. Returns a list of lists, each containing the nodes that form a connected component. Returns an empty list for an empty graph. """ list_of_components = [] component = [] # Not strictly necessary due to the whil...
[ "def", "get_connected_components", "(", "graph", ")", ":", "list_of_components", "=", "[", "]", "component", "=", "[", "]", "# Not strictly necessary due to the while loop structure, but it helps the automated analysis tools", "# Store a list of all unreached vertices", "unreached", ...
Finds all connected components of the graph. Returns a list of lists, each containing the nodes that form a connected component. Returns an empty list for an empty graph.
[ "Finds", "all", "connected", "components", "of", "the", "graph", ".", "Returns", "a", "list", "of", "lists", "each", "containing", "the", "nodes", "that", "form", "a", "connected", "component", ".", "Returns", "an", "empty", "list", "for", "an", "empty", "...
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/connected_components.py#L8-L41
42,270
jciskey/pygraph
pygraph/functions/connected_components.py
get_connected_components_as_subgraphs
def get_connected_components_as_subgraphs(graph): """Finds all connected components of the graph. Returns a list of graph objects, each representing a connected component. Returns an empty list for an empty graph. """ components = get_connected_components(graph) list_of_graphs = [] for c i...
python
def get_connected_components_as_subgraphs(graph): """Finds all connected components of the graph. Returns a list of graph objects, each representing a connected component. Returns an empty list for an empty graph. """ components = get_connected_components(graph) list_of_graphs = [] for c i...
[ "def", "get_connected_components_as_subgraphs", "(", "graph", ")", ":", "components", "=", "get_connected_components", "(", "graph", ")", "list_of_graphs", "=", "[", "]", "for", "c", "in", "components", ":", "edge_ids", "=", "set", "(", ")", "nodes", "=", "[",...
Finds all connected components of the graph. Returns a list of graph objects, each representing a connected component. Returns an empty list for an empty graph.
[ "Finds", "all", "connected", "components", "of", "the", "graph", ".", "Returns", "a", "list", "of", "graph", "objects", "each", "representing", "a", "connected", "component", ".", "Returns", "an", "empty", "list", "for", "an", "empty", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/connected_components.py#L44-L69
42,271
jciskey/pygraph
pygraph/classes/undirected_graph.py
UndirectedGraph.new_edge
def new_edge(self, node_a, node_b, cost=1): """Adds a new, undirected edge between node_a and node_b with a cost. Returns the edge id of the new edge.""" edge_id = super(UndirectedGraph, self).new_edge(node_a, node_b, cost) self.nodes[node_b]['edges'].append(edge_id) return edge_...
python
def new_edge(self, node_a, node_b, cost=1): """Adds a new, undirected edge between node_a and node_b with a cost. Returns the edge id of the new edge.""" edge_id = super(UndirectedGraph, self).new_edge(node_a, node_b, cost) self.nodes[node_b]['edges'].append(edge_id) return edge_...
[ "def", "new_edge", "(", "self", ",", "node_a", ",", "node_b", ",", "cost", "=", "1", ")", ":", "edge_id", "=", "super", "(", "UndirectedGraph", ",", "self", ")", ".", "new_edge", "(", "node_a", ",", "node_b", ",", "cost", ")", "self", ".", "nodes", ...
Adds a new, undirected edge between node_a and node_b with a cost. Returns the edge id of the new edge.
[ "Adds", "a", "new", "undirected", "edge", "between", "node_a", "and", "node_b", "with", "a", "cost", ".", "Returns", "the", "edge", "id", "of", "the", "new", "edge", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/undirected_graph.py#L20-L25
42,272
jciskey/pygraph
pygraph/classes/undirected_graph.py
UndirectedGraph.delete_edge_by_id
def delete_edge_by_id(self, edge_id): """Removes the edge identified by "edge_id" from the graph.""" edge = self.get_edge(edge_id) # Remove the edge from the "from node" # --Determine the from node from_node_id = edge['vertices'][0] from_node = self.get_node(from_node_id...
python
def delete_edge_by_id(self, edge_id): """Removes the edge identified by "edge_id" from the graph.""" edge = self.get_edge(edge_id) # Remove the edge from the "from node" # --Determine the from node from_node_id = edge['vertices'][0] from_node = self.get_node(from_node_id...
[ "def", "delete_edge_by_id", "(", "self", ",", "edge_id", ")", ":", "edge", "=", "self", ".", "get_edge", "(", "edge_id", ")", "# Remove the edge from the \"from node\"", "# --Determine the from node", "from_node_id", "=", "edge", "[", "'vertices'", "]", "[", "0", ...
Removes the edge identified by "edge_id" from the graph.
[ "Removes", "the", "edge", "identified", "by", "edge_id", "from", "the", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/classes/undirected_graph.py#L40-L62
42,273
jciskey/pygraph
pygraph/functions/spanning_tree.py
find_minimum_spanning_tree
def find_minimum_spanning_tree(graph): """Calculates a minimum spanning tree for a graph. Returns a list of edges that define the tree. Returns an empty list for an empty graph. """ mst = [] if graph.num_nodes() == 0: return mst if graph.num_edges() == 0: return mst con...
python
def find_minimum_spanning_tree(graph): """Calculates a minimum spanning tree for a graph. Returns a list of edges that define the tree. Returns an empty list for an empty graph. """ mst = [] if graph.num_nodes() == 0: return mst if graph.num_edges() == 0: return mst con...
[ "def", "find_minimum_spanning_tree", "(", "graph", ")", ":", "mst", "=", "[", "]", "if", "graph", ".", "num_nodes", "(", ")", "==", "0", ":", "return", "mst", "if", "graph", ".", "num_edges", "(", ")", "==", "0", ":", "return", "mst", "connected_compon...
Calculates a minimum spanning tree for a graph. Returns a list of edges that define the tree. Returns an empty list for an empty graph.
[ "Calculates", "a", "minimum", "spanning", "tree", "for", "a", "graph", ".", "Returns", "a", "list", "of", "edges", "that", "define", "the", "tree", ".", "Returns", "an", "empty", "list", "for", "an", "empty", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L8-L26
42,274
jciskey/pygraph
pygraph/functions/spanning_tree.py
find_minimum_spanning_tree_as_subgraph
def find_minimum_spanning_tree_as_subgraph(graph): """Calculates a minimum spanning tree and returns a graph representation.""" edge_list = find_minimum_spanning_tree(graph) subgraph = get_subgraph_from_edge_list(graph, edge_list) return subgraph
python
def find_minimum_spanning_tree_as_subgraph(graph): """Calculates a minimum spanning tree and returns a graph representation.""" edge_list = find_minimum_spanning_tree(graph) subgraph = get_subgraph_from_edge_list(graph, edge_list) return subgraph
[ "def", "find_minimum_spanning_tree_as_subgraph", "(", "graph", ")", ":", "edge_list", "=", "find_minimum_spanning_tree", "(", "graph", ")", "subgraph", "=", "get_subgraph_from_edge_list", "(", "graph", ",", "edge_list", ")", "return", "subgraph" ]
Calculates a minimum spanning tree and returns a graph representation.
[ "Calculates", "a", "minimum", "spanning", "tree", "and", "returns", "a", "graph", "representation", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L29-L34
42,275
jciskey/pygraph
pygraph/functions/spanning_tree.py
find_minimum_spanning_forest
def find_minimum_spanning_forest(graph): """Calculates the minimum spanning forest of a disconnected graph. Returns a list of lists, each containing the edges that define that tree. Returns an empty list for an empty graph. """ msf = [] if graph.num_nodes() == 0: return msf if graph...
python
def find_minimum_spanning_forest(graph): """Calculates the minimum spanning forest of a disconnected graph. Returns a list of lists, each containing the edges that define that tree. Returns an empty list for an empty graph. """ msf = [] if graph.num_nodes() == 0: return msf if graph...
[ "def", "find_minimum_spanning_forest", "(", "graph", ")", ":", "msf", "=", "[", "]", "if", "graph", ".", "num_nodes", "(", ")", "==", "0", ":", "return", "msf", "if", "graph", ".", "num_edges", "(", ")", "==", "0", ":", "return", "msf", "connected_comp...
Calculates the minimum spanning forest of a disconnected graph. Returns a list of lists, each containing the edges that define that tree. Returns an empty list for an empty graph.
[ "Calculates", "the", "minimum", "spanning", "forest", "of", "a", "disconnected", "graph", ".", "Returns", "a", "list", "of", "lists", "each", "containing", "the", "edges", "that", "define", "that", "tree", ".", "Returns", "an", "empty", "list", "for", "an", ...
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L37-L54
42,276
jciskey/pygraph
pygraph/functions/spanning_tree.py
find_minimum_spanning_forest_as_subgraphs
def find_minimum_spanning_forest_as_subgraphs(graph): """Calculates the minimum spanning forest and returns a list of trees as subgraphs.""" forest = find_minimum_spanning_forest(graph) list_of_subgraphs = [get_subgraph_from_edge_list(graph, edge_list) for edge_list in forest] return list_of_subgraphs
python
def find_minimum_spanning_forest_as_subgraphs(graph): """Calculates the minimum spanning forest and returns a list of trees as subgraphs.""" forest = find_minimum_spanning_forest(graph) list_of_subgraphs = [get_subgraph_from_edge_list(graph, edge_list) for edge_list in forest] return list_of_subgraphs
[ "def", "find_minimum_spanning_forest_as_subgraphs", "(", "graph", ")", ":", "forest", "=", "find_minimum_spanning_forest", "(", "graph", ")", "list_of_subgraphs", "=", "[", "get_subgraph_from_edge_list", "(", "graph", ",", "edge_list", ")", "for", "edge_list", "in", "...
Calculates the minimum spanning forest and returns a list of trees as subgraphs.
[ "Calculates", "the", "minimum", "spanning", "forest", "and", "returns", "a", "list", "of", "trees", "as", "subgraphs", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L57-L62
42,277
jciskey/pygraph
pygraph/functions/spanning_tree.py
kruskal_mst
def kruskal_mst(graph): """Implements Kruskal's Algorithm for finding minimum spanning trees. Assumes a non-empty, connected graph. """ edges_accepted = 0 ds = DisjointSet() pq = PriorityQueue() accepted_edges = [] label_lookup = {} nodes = graph.get_all_node_ids() num_vertices ...
python
def kruskal_mst(graph): """Implements Kruskal's Algorithm for finding minimum spanning trees. Assumes a non-empty, connected graph. """ edges_accepted = 0 ds = DisjointSet() pq = PriorityQueue() accepted_edges = [] label_lookup = {} nodes = graph.get_all_node_ids() num_vertices ...
[ "def", "kruskal_mst", "(", "graph", ")", ":", "edges_accepted", "=", "0", "ds", "=", "DisjointSet", "(", ")", "pq", "=", "PriorityQueue", "(", ")", "accepted_edges", "=", "[", "]", "label_lookup", "=", "{", "}", "nodes", "=", "graph", ".", "get_all_node_...
Implements Kruskal's Algorithm for finding minimum spanning trees. Assumes a non-empty, connected graph.
[ "Implements", "Kruskal", "s", "Algorithm", "for", "finding", "minimum", "spanning", "trees", ".", "Assumes", "a", "non", "-", "empty", "connected", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/spanning_tree.py#L65-L101
42,278
jciskey/pygraph
pygraph/functions/planarity/lipton-tarjan_algorithm.py
__get_cycle
def __get_cycle(graph, ordering, parent_lookup): """Gets the main cycle of the dfs tree.""" root_node = ordering[0] for i in range(2, len(ordering)): current_node = ordering[i] if graph.adjacent(current_node, root_node): path = [] while current_node != root_node: ...
python
def __get_cycle(graph, ordering, parent_lookup): """Gets the main cycle of the dfs tree.""" root_node = ordering[0] for i in range(2, len(ordering)): current_node = ordering[i] if graph.adjacent(current_node, root_node): path = [] while current_node != root_node: ...
[ "def", "__get_cycle", "(", "graph", ",", "ordering", ",", "parent_lookup", ")", ":", "root_node", "=", "ordering", "[", "0", "]", "for", "i", "in", "range", "(", "2", ",", "len", "(", "ordering", ")", ")", ":", "current_node", "=", "ordering", "[", "...
Gets the main cycle of the dfs tree.
[ "Gets", "the", "main", "cycle", "of", "the", "dfs", "tree", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/lipton-tarjan_algorithm.py#L3-L15
42,279
jciskey/pygraph
pygraph/functions/planarity/lipton-tarjan_algorithm.py
__get_segments_from_node
def __get_segments_from_node(node, graph): """Calculates the segments that can emanate from a particular node on the main cycle.""" list_of_segments = [] node_object = graph.get_node(node) for e in node_object['edges']: list_of_segments.append(e) return list_of_segments
python
def __get_segments_from_node(node, graph): """Calculates the segments that can emanate from a particular node on the main cycle.""" list_of_segments = [] node_object = graph.get_node(node) for e in node_object['edges']: list_of_segments.append(e) return list_of_segments
[ "def", "__get_segments_from_node", "(", "node", ",", "graph", ")", ":", "list_of_segments", "=", "[", "]", "node_object", "=", "graph", ".", "get_node", "(", "node", ")", "for", "e", "in", "node_object", "[", "'edges'", "]", ":", "list_of_segments", ".", "...
Calculates the segments that can emanate from a particular node on the main cycle.
[ "Calculates", "the", "segments", "that", "can", "emanate", "from", "a", "particular", "node", "on", "the", "main", "cycle", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/lipton-tarjan_algorithm.py#L18-L24
42,280
jciskey/pygraph
pygraph/functions/planarity/lipton-tarjan_algorithm.py
__get_segments_from_cycle
def __get_segments_from_cycle(graph, cycle_path): """Calculates the segments that emanate from the main cycle.""" list_of_segments = [] # We work through the cycle in a bottom-up fashion for n in cycle_path[::-1]: segments = __get_segments_from_node(n, graph) if segments: lis...
python
def __get_segments_from_cycle(graph, cycle_path): """Calculates the segments that emanate from the main cycle.""" list_of_segments = [] # We work through the cycle in a bottom-up fashion for n in cycle_path[::-1]: segments = __get_segments_from_node(n, graph) if segments: lis...
[ "def", "__get_segments_from_cycle", "(", "graph", ",", "cycle_path", ")", ":", "list_of_segments", "=", "[", "]", "# We work through the cycle in a bottom-up fashion", "for", "n", "in", "cycle_path", "[", ":", ":", "-", "1", "]", ":", "segments", "=", "__get_segme...
Calculates the segments that emanate from the main cycle.
[ "Calculates", "the", "segments", "that", "emanate", "from", "the", "main", "cycle", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/lipton-tarjan_algorithm.py#L27-L36
42,281
jciskey/pygraph
pygraph/helpers/functions.py
make_subgraph
def make_subgraph(graph, vertices, edges): """Converts a subgraph given by a list of vertices and edges into a graph object.""" # Copy the entire graph local_graph = copy.deepcopy(graph) # Remove all the edges that aren't in the list edges_to_delete = [x for x in local_graph.get_all_edge_ids() if x...
python
def make_subgraph(graph, vertices, edges): """Converts a subgraph given by a list of vertices and edges into a graph object.""" # Copy the entire graph local_graph = copy.deepcopy(graph) # Remove all the edges that aren't in the list edges_to_delete = [x for x in local_graph.get_all_edge_ids() if x...
[ "def", "make_subgraph", "(", "graph", ",", "vertices", ",", "edges", ")", ":", "# Copy the entire graph", "local_graph", "=", "copy", ".", "deepcopy", "(", "graph", ")", "# Remove all the edges that aren't in the list", "edges_to_delete", "=", "[", "x", "for", "x", ...
Converts a subgraph given by a list of vertices and edges into a graph object.
[ "Converts", "a", "subgraph", "given", "by", "a", "list", "of", "vertices", "and", "edges", "into", "a", "graph", "object", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L11-L26
42,282
jciskey/pygraph
pygraph/helpers/functions.py
convert_graph_directed_to_undirected
def convert_graph_directed_to_undirected(dg): """Converts a directed graph into an undirected graph. Directed edges are made undirected.""" udg = UndirectedGraph() # Copy the graph # --Copy nodes # --Copy edges udg.nodes = copy.deepcopy(dg.nodes) udg.edges = copy.deepcopy(dg.edges) udg...
python
def convert_graph_directed_to_undirected(dg): """Converts a directed graph into an undirected graph. Directed edges are made undirected.""" udg = UndirectedGraph() # Copy the graph # --Copy nodes # --Copy edges udg.nodes = copy.deepcopy(dg.nodes) udg.edges = copy.deepcopy(dg.edges) udg...
[ "def", "convert_graph_directed_to_undirected", "(", "dg", ")", ":", "udg", "=", "UndirectedGraph", "(", ")", "# Copy the graph", "# --Copy nodes", "# --Copy edges", "udg", ".", "nodes", "=", "copy", ".", "deepcopy", "(", "dg", ".", "nodes", ")", "udg", ".", "e...
Converts a directed graph into an undirected graph. Directed edges are made undirected.
[ "Converts", "a", "directed", "graph", "into", "an", "undirected", "graph", ".", "Directed", "edges", "are", "made", "undirected", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L29-L49
42,283
jciskey/pygraph
pygraph/helpers/functions.py
remove_duplicate_edges_directed
def remove_duplicate_edges_directed(dg): """Removes duplicate edges from a directed graph.""" # With directed edges, we can just hash the to and from node id tuples and if # a node happens to conflict with one that already exists, we delete it # --For aesthetic, we sort the edge ids so that lower edge ...
python
def remove_duplicate_edges_directed(dg): """Removes duplicate edges from a directed graph.""" # With directed edges, we can just hash the to and from node id tuples and if # a node happens to conflict with one that already exists, we delete it # --For aesthetic, we sort the edge ids so that lower edge ...
[ "def", "remove_duplicate_edges_directed", "(", "dg", ")", ":", "# With directed edges, we can just hash the to and from node id tuples and if", "# a node happens to conflict with one that already exists, we delete it", "# --For aesthetic, we sort the edge ids so that lower edge ids are kept", "loo...
Removes duplicate edges from a directed graph.
[ "Removes", "duplicate", "edges", "from", "a", "directed", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L52-L66
42,284
jciskey/pygraph
pygraph/helpers/functions.py
remove_duplicate_edges_undirected
def remove_duplicate_edges_undirected(udg): """Removes duplicate edges from an undirected graph.""" # With undirected edges, we need to hash both combinations of the to-from node ids, since a-b and b-a are equivalent # --For aesthetic, we sort the edge ids so that lower edges ids are kept lookup = {} ...
python
def remove_duplicate_edges_undirected(udg): """Removes duplicate edges from an undirected graph.""" # With undirected edges, we need to hash both combinations of the to-from node ids, since a-b and b-a are equivalent # --For aesthetic, we sort the edge ids so that lower edges ids are kept lookup = {} ...
[ "def", "remove_duplicate_edges_undirected", "(", "udg", ")", ":", "# With undirected edges, we need to hash both combinations of the to-from node ids, since a-b and b-a are equivalent", "# --For aesthetic, we sort the edge ids so that lower edges ids are kept", "lookup", "=", "{", "}", "edge...
Removes duplicate edges from an undirected graph.
[ "Removes", "duplicate", "edges", "from", "an", "undirected", "graph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L69-L83
42,285
jciskey/pygraph
pygraph/helpers/functions.py
get_vertices_from_edge_list
def get_vertices_from_edge_list(graph, edge_list): """Transforms a list of edges into a list of the nodes those edges connect. Returns a list of nodes, or an empty list if given an empty list. """ node_set = set() for edge_id in edge_list: edge = graph.get_edge(edge_id) a, b = edge['...
python
def get_vertices_from_edge_list(graph, edge_list): """Transforms a list of edges into a list of the nodes those edges connect. Returns a list of nodes, or an empty list if given an empty list. """ node_set = set() for edge_id in edge_list: edge = graph.get_edge(edge_id) a, b = edge['...
[ "def", "get_vertices_from_edge_list", "(", "graph", ",", "edge_list", ")", ":", "node_set", "=", "set", "(", ")", "for", "edge_id", "in", "edge_list", ":", "edge", "=", "graph", ".", "get_edge", "(", "edge_id", ")", "a", ",", "b", "=", "edge", "[", "'v...
Transforms a list of edges into a list of the nodes those edges connect. Returns a list of nodes, or an empty list if given an empty list.
[ "Transforms", "a", "list", "of", "edges", "into", "a", "list", "of", "the", "nodes", "those", "edges", "connect", ".", "Returns", "a", "list", "of", "nodes", "or", "an", "empty", "list", "if", "given", "an", "empty", "list", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L86-L97
42,286
jciskey/pygraph
pygraph/helpers/functions.py
get_subgraph_from_edge_list
def get_subgraph_from_edge_list(graph, edge_list): """Transforms a list of edges into a subgraph.""" node_list = get_vertices_from_edge_list(graph, edge_list) subgraph = make_subgraph(graph, node_list, edge_list) return subgraph
python
def get_subgraph_from_edge_list(graph, edge_list): """Transforms a list of edges into a subgraph.""" node_list = get_vertices_from_edge_list(graph, edge_list) subgraph = make_subgraph(graph, node_list, edge_list) return subgraph
[ "def", "get_subgraph_from_edge_list", "(", "graph", ",", "edge_list", ")", ":", "node_list", "=", "get_vertices_from_edge_list", "(", "graph", ",", "edge_list", ")", "subgraph", "=", "make_subgraph", "(", "graph", ",", "node_list", ",", "edge_list", ")", "return",...
Transforms a list of edges into a subgraph.
[ "Transforms", "a", "list", "of", "edges", "into", "a", "subgraph", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L100-L105
42,287
jciskey/pygraph
pygraph/helpers/functions.py
merge_graphs
def merge_graphs(main_graph, addition_graph): """Merges an ''addition_graph'' into the ''main_graph''. Returns a tuple of dictionaries, mapping old node ids and edge ids to new ids. """ node_mapping = {} edge_mapping = {} for node in addition_graph.get_all_node_objects(): node_id = nod...
python
def merge_graphs(main_graph, addition_graph): """Merges an ''addition_graph'' into the ''main_graph''. Returns a tuple of dictionaries, mapping old node ids and edge ids to new ids. """ node_mapping = {} edge_mapping = {} for node in addition_graph.get_all_node_objects(): node_id = nod...
[ "def", "merge_graphs", "(", "main_graph", ",", "addition_graph", ")", ":", "node_mapping", "=", "{", "}", "edge_mapping", "=", "{", "}", "for", "node", "in", "addition_graph", ".", "get_all_node_objects", "(", ")", ":", "node_id", "=", "node", "[", "'id'", ...
Merges an ''addition_graph'' into the ''main_graph''. Returns a tuple of dictionaries, mapping old node ids and edge ids to new ids.
[ "Merges", "an", "addition_graph", "into", "the", "main_graph", ".", "Returns", "a", "tuple", "of", "dictionaries", "mapping", "old", "node", "ids", "and", "edge", "ids", "to", "new", "ids", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L108-L129
42,288
jciskey/pygraph
pygraph/helpers/functions.py
create_graph_from_adjacency_matrix
def create_graph_from_adjacency_matrix(adjacency_matrix): """Generates a graph from an adjacency matrix specification. Returns a tuple containing the graph and a list-mapping of node ids to matrix column indices. The graph will be an UndirectedGraph if the provided adjacency matrix is symmetric. ...
python
def create_graph_from_adjacency_matrix(adjacency_matrix): """Generates a graph from an adjacency matrix specification. Returns a tuple containing the graph and a list-mapping of node ids to matrix column indices. The graph will be an UndirectedGraph if the provided adjacency matrix is symmetric. ...
[ "def", "create_graph_from_adjacency_matrix", "(", "adjacency_matrix", ")", ":", "if", "is_adjacency_matrix_symmetric", "(", "adjacency_matrix", ")", ":", "graph", "=", "UndirectedGraph", "(", ")", "else", ":", "graph", "=", "DirectedGraph", "(", ")", "node_column_mapp...
Generates a graph from an adjacency matrix specification. Returns a tuple containing the graph and a list-mapping of node ids to matrix column indices. The graph will be an UndirectedGraph if the provided adjacency matrix is symmetric. The graph will be a DirectedGraph if the provided adjacency ma...
[ "Generates", "a", "graph", "from", "an", "adjacency", "matrix", "specification", ".", "Returns", "a", "tuple", "containing", "the", "graph", "and", "a", "list", "-", "mapping", "of", "node", "ids", "to", "matrix", "column", "indices", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/functions.py#L132-L160
42,289
jciskey/pygraph
pygraph/helpers/classes/disjoint_set.py
DisjointSet.add_set
def add_set(self): """Adds a new set to the forest. Returns a label by which the new set can be referenced """ self.__label_counter += 1 new_label = self.__label_counter self.__forest[new_label] = -1 # All new sets have their parent set to themselves self.__set_c...
python
def add_set(self): """Adds a new set to the forest. Returns a label by which the new set can be referenced """ self.__label_counter += 1 new_label = self.__label_counter self.__forest[new_label] = -1 # All new sets have their parent set to themselves self.__set_c...
[ "def", "add_set", "(", "self", ")", ":", "self", ".", "__label_counter", "+=", "1", "new_label", "=", "self", ".", "__label_counter", "self", ".", "__forest", "[", "new_label", "]", "=", "-", "1", "# All new sets have their parent set to themselves", "self", "."...
Adds a new set to the forest. Returns a label by which the new set can be referenced
[ "Adds", "a", "new", "set", "to", "the", "forest", ".", "Returns", "a", "label", "by", "which", "the", "new", "set", "can", "be", "referenced" ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/classes/disjoint_set.py#L21-L29
42,290
jciskey/pygraph
pygraph/helpers/classes/disjoint_set.py
DisjointSet.find
def find(self, node_label): """Finds the set containing the node_label. Returns the set label. """ queue = [] current_node = node_label while self.__forest[current_node] >= 0: queue.append(current_node) current_node = self.__forest[current_node] ...
python
def find(self, node_label): """Finds the set containing the node_label. Returns the set label. """ queue = [] current_node = node_label while self.__forest[current_node] >= 0: queue.append(current_node) current_node = self.__forest[current_node] ...
[ "def", "find", "(", "self", ",", "node_label", ")", ":", "queue", "=", "[", "]", "current_node", "=", "node_label", "while", "self", ".", "__forest", "[", "current_node", "]", ">=", "0", ":", "queue", ".", "append", "(", "current_node", ")", "current_nod...
Finds the set containing the node_label. Returns the set label.
[ "Finds", "the", "set", "containing", "the", "node_label", ".", "Returns", "the", "set", "label", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/classes/disjoint_set.py#L31-L46
42,291
jciskey/pygraph
pygraph/helpers/classes/disjoint_set.py
DisjointSet.union
def union(self, label_a, label_b): """Joins two sets into a single new set. label_a, label_b can be any nodes within the sets """ # Base case to avoid work if label_a == label_b: return # Find the tree root of each node root_a = self.find(label_a) ...
python
def union(self, label_a, label_b): """Joins two sets into a single new set. label_a, label_b can be any nodes within the sets """ # Base case to avoid work if label_a == label_b: return # Find the tree root of each node root_a = self.find(label_a) ...
[ "def", "union", "(", "self", ",", "label_a", ",", "label_b", ")", ":", "# Base case to avoid work", "if", "label_a", "==", "label_b", ":", "return", "# Find the tree root of each node", "root_a", "=", "self", ".", "find", "(", "label_a", ")", "root_b", "=", "s...
Joins two sets into a single new set. label_a, label_b can be any nodes within the sets
[ "Joins", "two", "sets", "into", "a", "single", "new", "set", ".", "label_a", "label_b", "can", "be", "any", "nodes", "within", "the", "sets" ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/classes/disjoint_set.py#L48-L65
42,292
jciskey/pygraph
pygraph/helpers/classes/disjoint_set.py
DisjointSet.__internal_union
def __internal_union(self, root_a, root_b): """Internal function to join two set trees specified by root_a and root_b. Assumes root_a and root_b are distinct. """ # Merge the trees, smaller to larger update_rank = False # --Determine the larger tree rank_a = self....
python
def __internal_union(self, root_a, root_b): """Internal function to join two set trees specified by root_a and root_b. Assumes root_a and root_b are distinct. """ # Merge the trees, smaller to larger update_rank = False # --Determine the larger tree rank_a = self....
[ "def", "__internal_union", "(", "self", ",", "root_a", ",", "root_b", ")", ":", "# Merge the trees, smaller to larger", "update_rank", "=", "False", "# --Determine the larger tree", "rank_a", "=", "self", ".", "__forest", "[", "root_a", "]", "rank_b", "=", "self", ...
Internal function to join two set trees specified by root_a and root_b. Assumes root_a and root_b are distinct.
[ "Internal", "function", "to", "join", "two", "set", "trees", "specified", "by", "root_a", "and", "root_b", ".", "Assumes", "root_a", "and", "root_b", "are", "distinct", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/helpers/classes/disjoint_set.py#L67-L88
42,293
jciskey/pygraph
pygraph/functions/planarity/functions.py
is_planar
def is_planar(graph): """Determines whether a graph is planar or not.""" # Determine connected components as subgraphs; their planarity is independent of each other connected_components = get_connected_components_as_subgraphs(graph) for component in connected_components: # Biconnected components...
python
def is_planar(graph): """Determines whether a graph is planar or not.""" # Determine connected components as subgraphs; their planarity is independent of each other connected_components = get_connected_components_as_subgraphs(graph) for component in connected_components: # Biconnected components...
[ "def", "is_planar", "(", "graph", ")", ":", "# Determine connected components as subgraphs; their planarity is independent of each other", "connected_components", "=", "get_connected_components_as_subgraphs", "(", "graph", ")", "for", "component", "in", "connected_components", ":",...
Determines whether a graph is planar or not.
[ "Determines", "whether", "a", "graph", "is", "planar", "or", "not", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/functions.py#L9-L20
42,294
jciskey/pygraph
pygraph/functions/planarity/functions.py
__is_subgraph_planar
def __is_subgraph_planar(graph): """Internal function to determine if a subgraph is planar.""" # --First pass: Determine edge and vertex counts validate Euler's Formula num_nodes = graph.num_nodes() num_edges = graph.num_edges() # --We can guarantee that if there are 4 or less nodes, then the graph...
python
def __is_subgraph_planar(graph): """Internal function to determine if a subgraph is planar.""" # --First pass: Determine edge and vertex counts validate Euler's Formula num_nodes = graph.num_nodes() num_edges = graph.num_edges() # --We can guarantee that if there are 4 or less nodes, then the graph...
[ "def", "__is_subgraph_planar", "(", "graph", ")", ":", "# --First pass: Determine edge and vertex counts validate Euler's Formula", "num_nodes", "=", "graph", ".", "num_nodes", "(", ")", "num_edges", "=", "graph", ".", "num_edges", "(", ")", "# --We can guarantee that if th...
Internal function to determine if a subgraph is planar.
[ "Internal", "function", "to", "determine", "if", "a", "subgraph", "is", "planar", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/functions.py#L23-L39
42,295
jciskey/pygraph
pygraph/functions/planarity/kocay_algorithm.py
__setup_dfs_data
def __setup_dfs_data(graph, adj): """Sets up the dfs_data object, for consistency.""" dfs_data = __get_dfs_data(graph, adj) dfs_data['graph'] = graph dfs_data['adj'] = adj L1, L2 = __low_point_dfs(dfs_data) dfs_data['lowpoint_1_lookup'] = L1 dfs_data['lowpoint_2_lookup'] = L2 edge_wei...
python
def __setup_dfs_data(graph, adj): """Sets up the dfs_data object, for consistency.""" dfs_data = __get_dfs_data(graph, adj) dfs_data['graph'] = graph dfs_data['adj'] = adj L1, L2 = __low_point_dfs(dfs_data) dfs_data['lowpoint_1_lookup'] = L1 dfs_data['lowpoint_2_lookup'] = L2 edge_wei...
[ "def", "__setup_dfs_data", "(", "graph", ",", "adj", ")", ":", "dfs_data", "=", "__get_dfs_data", "(", "graph", ",", "adj", ")", "dfs_data", "[", "'graph'", "]", "=", "graph", "dfs_data", "[", "'adj'", "]", "=", "adj", "L1", ",", "L2", "=", "__low_poin...
Sets up the dfs_data object, for consistency.
[ "Sets", "up", "the", "dfs_data", "object", "for", "consistency", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L45-L59
42,296
jciskey/pygraph
pygraph/functions/planarity/kocay_algorithm.py
__calculate_edge_weights
def __calculate_edge_weights(dfs_data): """Calculates the weight of each edge, for embedding-order sorting.""" graph = dfs_data['graph'] weights = {} for edge_id in graph.get_all_edge_ids(): edge_weight = __edge_weight(edge_id, dfs_data) weights[edge_id] = edge_weight return weight...
python
def __calculate_edge_weights(dfs_data): """Calculates the weight of each edge, for embedding-order sorting.""" graph = dfs_data['graph'] weights = {} for edge_id in graph.get_all_edge_ids(): edge_weight = __edge_weight(edge_id, dfs_data) weights[edge_id] = edge_weight return weight...
[ "def", "__calculate_edge_weights", "(", "dfs_data", ")", ":", "graph", "=", "dfs_data", "[", "'graph'", "]", "weights", "=", "{", "}", "for", "edge_id", "in", "graph", ".", "get_all_edge_ids", "(", ")", ":", "edge_weight", "=", "__edge_weight", "(", "edge_id...
Calculates the weight of each edge, for embedding-order sorting.
[ "Calculates", "the", "weight", "of", "each", "edge", "for", "embedding", "-", "order", "sorting", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L68-L77
42,297
jciskey/pygraph
pygraph/functions/planarity/kocay_algorithm.py
__sort_adjacency_lists
def __sort_adjacency_lists(dfs_data): """Sorts the adjacency list representation by the edge weights.""" new_adjacency_lists = {} adjacency_lists = dfs_data['adj'] edge_weights = dfs_data['edge_weights'] edge_lookup = dfs_data['edge_lookup'] for node_id, adj_list in list(adjacency_lists.items(...
python
def __sort_adjacency_lists(dfs_data): """Sorts the adjacency list representation by the edge weights.""" new_adjacency_lists = {} adjacency_lists = dfs_data['adj'] edge_weights = dfs_data['edge_weights'] edge_lookup = dfs_data['edge_lookup'] for node_id, adj_list in list(adjacency_lists.items(...
[ "def", "__sort_adjacency_lists", "(", "dfs_data", ")", ":", "new_adjacency_lists", "=", "{", "}", "adjacency_lists", "=", "dfs_data", "[", "'adj'", "]", "edge_weights", "=", "dfs_data", "[", "'edge_weights'", "]", "edge_lookup", "=", "dfs_data", "[", "'edge_lookup...
Sorts the adjacency list representation by the edge weights.
[ "Sorts", "the", "adjacency", "list", "representation", "by", "the", "edge", "weights", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L80-L105
42,298
jciskey/pygraph
pygraph/functions/planarity/kocay_algorithm.py
__branch_point_dfs_recursive
def __branch_point_dfs_recursive(u, large_n, b, stem, dfs_data): """A recursive implementation of the BranchPtDFS function, as defined on page 14 of the paper.""" first_vertex = dfs_data['adj'][u][0] large_w = wt(u, first_vertex, dfs_data) if large_w % 2 == 0: large_w += 1 v_I = 0 v_II =...
python
def __branch_point_dfs_recursive(u, large_n, b, stem, dfs_data): """A recursive implementation of the BranchPtDFS function, as defined on page 14 of the paper.""" first_vertex = dfs_data['adj'][u][0] large_w = wt(u, first_vertex, dfs_data) if large_w % 2 == 0: large_w += 1 v_I = 0 v_II =...
[ "def", "__branch_point_dfs_recursive", "(", "u", ",", "large_n", ",", "b", ",", "stem", ",", "dfs_data", ")", ":", "first_vertex", "=", "dfs_data", "[", "'adj'", "]", "[", "u", "]", "[", "0", "]", "large_w", "=", "wt", "(", "u", ",", "first_vertex", ...
A recursive implementation of the BranchPtDFS function, as defined on page 14 of the paper.
[ "A", "recursive", "implementation", "of", "the", "BranchPtDFS", "function", "as", "defined", "on", "page", "14", "of", "the", "paper", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L123-L180
42,299
jciskey/pygraph
pygraph/functions/planarity/kocay_algorithm.py
__embed_branch
def __embed_branch(dfs_data): """Builds the combinatorial embedding of the graph. Returns whether the graph is planar.""" u = dfs_data['ordering'][0] dfs_data['LF'] = [] dfs_data['RF'] = [] dfs_data['FG'] = {} n = dfs_data['graph'].num_nodes() f0 = (0, n) g0 = (0, n) L0 = {'u': 0, 'v...
python
def __embed_branch(dfs_data): """Builds the combinatorial embedding of the graph. Returns whether the graph is planar.""" u = dfs_data['ordering'][0] dfs_data['LF'] = [] dfs_data['RF'] = [] dfs_data['FG'] = {} n = dfs_data['graph'].num_nodes() f0 = (0, n) g0 = (0, n) L0 = {'u': 0, 'v...
[ "def", "__embed_branch", "(", "dfs_data", ")", ":", "u", "=", "dfs_data", "[", "'ordering'", "]", "[", "0", "]", "dfs_data", "[", "'LF'", "]", "=", "[", "]", "dfs_data", "[", "'RF'", "]", "=", "[", "]", "dfs_data", "[", "'FG'", "]", "=", "{", "}"...
Builds the combinatorial embedding of the graph. Returns whether the graph is planar.
[ "Builds", "the", "combinatorial", "embedding", "of", "the", "graph", ".", "Returns", "whether", "the", "graph", "is", "planar", "." ]
037bb2f32503fecb60d62921f9766d54109f15e2
https://github.com/jciskey/pygraph/blob/037bb2f32503fecb60d62921f9766d54109f15e2/pygraph/functions/planarity/kocay_algorithm.py#L183-L209