repository_name
stringlengths
7
55
func_path_in_repository
stringlengths
4
223
func_name
stringlengths
1
134
whole_func_string
stringlengths
75
104k
language
stringclasses
1 value
func_code_string
stringlengths
75
104k
func_code_tokens
listlengths
19
28.4k
func_documentation_string
stringlengths
1
46.9k
func_documentation_tokens
listlengths
1
1.97k
split_name
stringclasses
1 value
func_code_url
stringlengths
87
315
davenquinn/Attitude
attitude/geom/__init__.py
fit_angle
def fit_angle(fit1, fit2, degrees=True): """ Finds the angle between the nominal vectors """ return N.degrees(angle(fit1.normal,fit2.normal))
python
def fit_angle(fit1, fit2, degrees=True): """ Finds the angle between the nominal vectors """ return N.degrees(angle(fit1.normal,fit2.normal))
[ "def", "fit_angle", "(", "fit1", ",", "fit2", ",", "degrees", "=", "True", ")", ":", "return", "N", ".", "degrees", "(", "angle", "(", "fit1", ".", "normal", ",", "fit2", ".", "normal", ")", ")" ]
Finds the angle between the nominal vectors
[ "Finds", "the", "angle", "between", "the", "nominal", "vectors" ]
train
https://github.com/davenquinn/Attitude/blob/2ce97b9aba0aa5deedc6617c2315e07e6396d240/attitude/geom/__init__.py#L17-L21
davenquinn/Attitude
attitude/geom/__init__.py
fit_similarity
def fit_similarity(fit1, fit2): """ Distance apart for vectors, given in standard deviations """ cov1 = aligned_covariance(fit1) cov2 = aligned_covariance(fit2) if fit2.axes[2,2] < 0: cov2 *= -1 v0 = fit1.normal-fit2.normal cov0 = cov1+cov2 # Axes are aligned, so no covarianc...
python
def fit_similarity(fit1, fit2): """ Distance apart for vectors, given in standard deviations """ cov1 = aligned_covariance(fit1) cov2 = aligned_covariance(fit2) if fit2.axes[2,2] < 0: cov2 *= -1 v0 = fit1.normal-fit2.normal cov0 = cov1+cov2 # Axes are aligned, so no covarianc...
[ "def", "fit_similarity", "(", "fit1", ",", "fit2", ")", ":", "cov1", "=", "aligned_covariance", "(", "fit1", ")", "cov2", "=", "aligned_covariance", "(", "fit2", ")", "if", "fit2", ".", "axes", "[", "2", ",", "2", "]", "<", "0", ":", "cov2", "*=", ...
Distance apart for vectors, given in standard deviations
[ "Distance", "apart", "for", "vectors", "given", "in", "standard", "deviations" ]
train
https://github.com/davenquinn/Attitude/blob/2ce97b9aba0aa5deedc6617c2315e07e6396d240/attitude/geom/__init__.py#L23-L41
davenquinn/Attitude
attitude/geom/__init__.py
axis_aligned_transforms
def axis_aligned_transforms(): """ Generates three transformation matrices to map three-dimensional data down to slices on the xy, xz and yz planes, respectively. The typical use case for this is to iterate over the results of this method to provide arguments to e.g. the `HyperbolicErrors` f...
python
def axis_aligned_transforms(): """ Generates three transformation matrices to map three-dimensional data down to slices on the xy, xz and yz planes, respectively. The typical use case for this is to iterate over the results of this method to provide arguments to e.g. the `HyperbolicErrors` f...
[ "def", "axis_aligned_transforms", "(", ")", ":", "I", "=", "N", ".", "eye", "(", "3", ")", "xy", "=", "I", "[", ":", "2", "]", "xz", "=", "N", ".", "vstack", "(", "(", "I", "[", "0", "]", ",", "I", "[", "2", "]", ")", ")", "yz", "=", "I...
Generates three transformation matrices to map three-dimensional data down to slices on the xy, xz and yz planes, respectively. The typical use case for this is to iterate over the results of this method to provide arguments to e.g. the `HyperbolicErrors` function.
[ "Generates", "three", "transformation", "matrices", "to", "map", "three", "-", "dimensional", "data", "down", "to", "slices", "on", "the", "xy", "xz", "and", "yz", "planes", "respectively", ".", "The", "typical", "use", "case", "for", "this", "is", "to", "...
train
https://github.com/davenquinn/Attitude/blob/2ce97b9aba0aa5deedc6617c2315e07e6396d240/attitude/geom/__init__.py#L43-L56
RudolfCardinal/pythonlib
cardinal_pythonlib/plot.py
png_img_html_from_pyplot_figure
def png_img_html_from_pyplot_figure(fig: "Figure", dpi: int = 100, extra_html_class: str = None) -> str: """ Converts a ``pyplot`` figure to an HTML IMG tag with encapsulated PNG. """ if fig is None: return "" # Make a f...
python
def png_img_html_from_pyplot_figure(fig: "Figure", dpi: int = 100, extra_html_class: str = None) -> str: """ Converts a ``pyplot`` figure to an HTML IMG tag with encapsulated PNG. """ if fig is None: return "" # Make a f...
[ "def", "png_img_html_from_pyplot_figure", "(", "fig", ":", "\"Figure\"", ",", "dpi", ":", "int", "=", "100", ",", "extra_html_class", ":", "str", "=", "None", ")", "->", "str", ":", "if", "fig", "is", "None", ":", "return", "\"\"", "# Make a file-like object...
Converts a ``pyplot`` figure to an HTML IMG tag with encapsulated PNG.
[ "Converts", "a", "pyplot", "figure", "to", "an", "HTML", "IMG", "tag", "with", "encapsulated", "PNG", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/plot.py#L52-L70
RudolfCardinal/pythonlib
cardinal_pythonlib/plot.py
svg_html_from_pyplot_figure
def svg_html_from_pyplot_figure(fig: "Figure") -> str: """ Converts a ``pyplot`` figure to an SVG tag. """ if fig is None: return "" memfile = io.BytesIO() # StringIO doesn't like mixing str/unicode fig.savefig(memfile, format="svg") return memfile.getvalue().decode("utf-8")
python
def svg_html_from_pyplot_figure(fig: "Figure") -> str: """ Converts a ``pyplot`` figure to an SVG tag. """ if fig is None: return "" memfile = io.BytesIO() # StringIO doesn't like mixing str/unicode fig.savefig(memfile, format="svg") return memfile.getvalue().decode("utf-8")
[ "def", "svg_html_from_pyplot_figure", "(", "fig", ":", "\"Figure\"", ")", "->", "str", ":", "if", "fig", "is", "None", ":", "return", "\"\"", "memfile", "=", "io", ".", "BytesIO", "(", ")", "# StringIO doesn't like mixing str/unicode", "fig", ".", "savefig", "...
Converts a ``pyplot`` figure to an SVG tag.
[ "Converts", "a", "pyplot", "figure", "to", "an", "SVG", "tag", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/plot.py#L73-L81
RudolfCardinal/pythonlib
cardinal_pythonlib/plot.py
set_matplotlib_fontsize
def set_matplotlib_fontsize(matplotlib: ModuleType, fontsize: Union[int, float] = 12) -> None: """ Sets the current font size within the ``matplotlib`` library. **WARNING:** not an appropriate method for multithreaded environments, as it writes (indirectly) to ``matplotlib``...
python
def set_matplotlib_fontsize(matplotlib: ModuleType, fontsize: Union[int, float] = 12) -> None: """ Sets the current font size within the ``matplotlib`` library. **WARNING:** not an appropriate method for multithreaded environments, as it writes (indirectly) to ``matplotlib``...
[ "def", "set_matplotlib_fontsize", "(", "matplotlib", ":", "ModuleType", ",", "fontsize", ":", "Union", "[", "int", ",", "float", "]", "=", "12", ")", "->", "None", ":", "font", "=", "{", "# http://stackoverflow.com/questions/3899980", "# http://matplotlib.org/users/...
Sets the current font size within the ``matplotlib`` library. **WARNING:** not an appropriate method for multithreaded environments, as it writes (indirectly) to ``matplotlib`` global objects. See CamCOPS for alternative methods.
[ "Sets", "the", "current", "font", "size", "within", "the", "matplotlib", "library", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/plot.py#L89-L117
Autodesk/cryptorito
cryptorito/cli.py
massage_keys
def massage_keys(keys): """Goes through list of GPG/Keybase keys. For the keybase keys it will attempt to look up the GPG key""" m_keys = [] for key in keys: if key.startswith('keybase:'): m_keys.append(cryptorito.key_from_keybase(key[8:])['fingerprint']) else: m_...
python
def massage_keys(keys): """Goes through list of GPG/Keybase keys. For the keybase keys it will attempt to look up the GPG key""" m_keys = [] for key in keys: if key.startswith('keybase:'): m_keys.append(cryptorito.key_from_keybase(key[8:])['fingerprint']) else: m_...
[ "def", "massage_keys", "(", "keys", ")", ":", "m_keys", "=", "[", "]", "for", "key", "in", "keys", ":", "if", "key", ".", "startswith", "(", "'keybase:'", ")", ":", "m_keys", ".", "append", "(", "cryptorito", ".", "key_from_keybase", "(", "key", "[", ...
Goes through list of GPG/Keybase keys. For the keybase keys it will attempt to look up the GPG key
[ "Goes", "through", "list", "of", "GPG", "/", "Keybase", "keys", ".", "For", "the", "keybase", "keys", "it", "will", "attempt", "to", "look", "up", "the", "GPG", "key" ]
train
https://github.com/Autodesk/cryptorito/blob/277fc7cc42c31c5bc37e26d8bf5a2ac746a6ea85/cryptorito/cli.py#L8-L18
Autodesk/cryptorito
cryptorito/cli.py
encrypt_file
def encrypt_file(src, dest, csv_keys): """Encrypt a file with the specific GPG keys and write out to the specified path""" keys = massage_keys(csv_keys.split(',')) cryptorito.encrypt(src, dest, keys)
python
def encrypt_file(src, dest, csv_keys): """Encrypt a file with the specific GPG keys and write out to the specified path""" keys = massage_keys(csv_keys.split(',')) cryptorito.encrypt(src, dest, keys)
[ "def", "encrypt_file", "(", "src", ",", "dest", ",", "csv_keys", ")", ":", "keys", "=", "massage_keys", "(", "csv_keys", ".", "split", "(", "','", ")", ")", "cryptorito", ".", "encrypt", "(", "src", ",", "dest", ",", "keys", ")" ]
Encrypt a file with the specific GPG keys and write out to the specified path
[ "Encrypt", "a", "file", "with", "the", "specific", "GPG", "keys", "and", "write", "out", "to", "the", "specified", "path" ]
train
https://github.com/Autodesk/cryptorito/blob/277fc7cc42c31c5bc37e26d8bf5a2ac746a6ea85/cryptorito/cli.py#L21-L25
Autodesk/cryptorito
cryptorito/cli.py
encrypt_var
def encrypt_var(csv_keys): """Encrypt what comes in from stdin and return base64 encrypted against the specified keys, returning on stdout""" keys = massage_keys(csv_keys.split(',')) data = sys.stdin.read() encrypted = cryptorito.encrypt_var(data, keys) print(cryptorito.portable_b64encode(encryp...
python
def encrypt_var(csv_keys): """Encrypt what comes in from stdin and return base64 encrypted against the specified keys, returning on stdout""" keys = massage_keys(csv_keys.split(',')) data = sys.stdin.read() encrypted = cryptorito.encrypt_var(data, keys) print(cryptorito.portable_b64encode(encryp...
[ "def", "encrypt_var", "(", "csv_keys", ")", ":", "keys", "=", "massage_keys", "(", "csv_keys", ".", "split", "(", "','", ")", ")", "data", "=", "sys", ".", "stdin", ".", "read", "(", ")", "encrypted", "=", "cryptorito", ".", "encrypt_var", "(", "data",...
Encrypt what comes in from stdin and return base64 encrypted against the specified keys, returning on stdout
[ "Encrypt", "what", "comes", "in", "from", "stdin", "and", "return", "base64", "encrypted", "against", "the", "specified", "keys", "returning", "on", "stdout" ]
train
https://github.com/Autodesk/cryptorito/blob/277fc7cc42c31c5bc37e26d8bf5a2ac746a6ea85/cryptorito/cli.py#L33-L39
Autodesk/cryptorito
cryptorito/cli.py
decrypt_var
def decrypt_var(passphrase=None): """Decrypt what comes in from stdin (base64'd) and write it out to stdout""" encrypted = cryptorito.portable_b64decode(sys.stdin.read()) print(cryptorito.decrypt_var(encrypted, passphrase))
python
def decrypt_var(passphrase=None): """Decrypt what comes in from stdin (base64'd) and write it out to stdout""" encrypted = cryptorito.portable_b64decode(sys.stdin.read()) print(cryptorito.decrypt_var(encrypted, passphrase))
[ "def", "decrypt_var", "(", "passphrase", "=", "None", ")", ":", "encrypted", "=", "cryptorito", ".", "portable_b64decode", "(", "sys", ".", "stdin", ".", "read", "(", ")", ")", "print", "(", "cryptorito", ".", "decrypt_var", "(", "encrypted", ",", "passphr...
Decrypt what comes in from stdin (base64'd) and write it out to stdout
[ "Decrypt", "what", "comes", "in", "from", "stdin", "(", "base64", "d", ")", "and", "write", "it", "out", "to", "stdout" ]
train
https://github.com/Autodesk/cryptorito/blob/277fc7cc42c31c5bc37e26d8bf5a2ac746a6ea85/cryptorito/cli.py#L42-L46
Autodesk/cryptorito
cryptorito/cli.py
import_keybase
def import_keybase(useropt): """Imports a public GPG key from Keybase""" public_key = None u_bits = useropt.split(':') username = u_bits[0] if len(u_bits) == 1: public_key = cryptorito.key_from_keybase(username) else: fingerprint = u_bits[1] public_key = cryptorito.key_fr...
python
def import_keybase(useropt): """Imports a public GPG key from Keybase""" public_key = None u_bits = useropt.split(':') username = u_bits[0] if len(u_bits) == 1: public_key = cryptorito.key_from_keybase(username) else: fingerprint = u_bits[1] public_key = cryptorito.key_fr...
[ "def", "import_keybase", "(", "useropt", ")", ":", "public_key", "=", "None", "u_bits", "=", "useropt", ".", "split", "(", "':'", ")", "username", "=", "u_bits", "[", "0", "]", "if", "len", "(", "u_bits", ")", "==", "1", ":", "public_key", "=", "cryp...
Imports a public GPG key from Keybase
[ "Imports", "a", "public", "GPG", "key", "from", "Keybase" ]
train
https://github.com/Autodesk/cryptorito/blob/277fc7cc42c31c5bc37e26d8bf5a2ac746a6ea85/cryptorito/cli.py#L57-L72
Autodesk/cryptorito
cryptorito/cli.py
do_thing
def do_thing(): """Execute command line cryptorito actions""" if len(sys.argv) == 5 and sys.argv[1] == "encrypt_file": encrypt_file(sys.argv[2], sys.argv[3], sys.argv[4]) elif len(sys.argv) == 4 and sys.argv[1] == "decrypt_file": decrypt_file(sys.argv[2], sys.argv[3]) elif len(sys.argv) ...
python
def do_thing(): """Execute command line cryptorito actions""" if len(sys.argv) == 5 and sys.argv[1] == "encrypt_file": encrypt_file(sys.argv[2], sys.argv[3], sys.argv[4]) elif len(sys.argv) == 4 and sys.argv[1] == "decrypt_file": decrypt_file(sys.argv[2], sys.argv[3]) elif len(sys.argv) ...
[ "def", "do_thing", "(", ")", ":", "if", "len", "(", "sys", ".", "argv", ")", "==", "5", "and", "sys", ".", "argv", "[", "1", "]", "==", "\"encrypt_file\"", ":", "encrypt_file", "(", "sys", ".", "argv", "[", "2", "]", ",", "sys", ".", "argv", "[...
Execute command line cryptorito actions
[ "Execute", "command", "line", "cryptorito", "actions" ]
train
https://github.com/Autodesk/cryptorito/blob/277fc7cc42c31c5bc37e26d8bf5a2ac746a6ea85/cryptorito/cli.py#L81-L102
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
get_monochrome_handler
def get_monochrome_handler( extranames: List[str] = None, with_process_id: bool = False, with_thread_id: bool = False, stream: TextIO = None) -> logging.StreamHandler: """ Gets a monochrome log handler using a standard format. Args: extranames: additional names to ap...
python
def get_monochrome_handler( extranames: List[str] = None, with_process_id: bool = False, with_thread_id: bool = False, stream: TextIO = None) -> logging.StreamHandler: """ Gets a monochrome log handler using a standard format. Args: extranames: additional names to ap...
[ "def", "get_monochrome_handler", "(", "extranames", ":", "List", "[", "str", "]", "=", "None", ",", "with_process_id", ":", "bool", "=", "False", ",", "with_thread_id", ":", "bool", "=", "False", ",", "stream", ":", "TextIO", "=", "None", ")", "->", "log...
Gets a monochrome log handler using a standard format. Args: extranames: additional names to append to the logger's name with_process_id: include the process ID in the logger's name? with_thread_id: include the thread ID in the logger's name? stream: ``TextIO`` stream to send log ou...
[ "Gets", "a", "monochrome", "log", "handler", "using", "a", "standard", "format", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L105-L137
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
get_colour_handler
def get_colour_handler(extranames: List[str] = None, with_process_id: bool = False, with_thread_id: bool = False, stream: TextIO = None) -> logging.StreamHandler: """ Gets a colour log handler using a standard format. Args: extran...
python
def get_colour_handler(extranames: List[str] = None, with_process_id: bool = False, with_thread_id: bool = False, stream: TextIO = None) -> logging.StreamHandler: """ Gets a colour log handler using a standard format. Args: extran...
[ "def", "get_colour_handler", "(", "extranames", ":", "List", "[", "str", "]", "=", "None", ",", "with_process_id", ":", "bool", "=", "False", ",", "with_thread_id", ":", "bool", "=", "False", ",", "stream", ":", "TextIO", "=", "None", ")", "->", "logging...
Gets a colour log handler using a standard format. Args: extranames: additional names to append to the logger's name with_process_id: include the process ID in the logger's name? with_thread_id: include the thread ID in the logger's name? stream: ``TextIO`` stream to send log output...
[ "Gets", "a", "colour", "log", "handler", "using", "a", "standard", "format", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L140-L176
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
configure_logger_for_colour
def configure_logger_for_colour(logger: logging.Logger, level: int = logging.INFO, remove_existing: bool = False, extranames: List[str] = None, with_process_id: bool = False, ...
python
def configure_logger_for_colour(logger: logging.Logger, level: int = logging.INFO, remove_existing: bool = False, extranames: List[str] = None, with_process_id: bool = False, ...
[ "def", "configure_logger_for_colour", "(", "logger", ":", "logging", ".", "Logger", ",", "level", ":", "int", "=", "logging", ".", "INFO", ",", "remove_existing", ":", "bool", "=", "False", ",", "extranames", ":", "List", "[", "str", "]", "=", "None", ",...
Applies a preconfigured datetime/colour scheme to a logger. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config. Args: logger: logger to modify level: log level to set remove_existing: remove existing ha...
[ "Applies", "a", "preconfigured", "datetime", "/", "colour", "scheme", "to", "a", "logger", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L179-L206
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
main_only_quicksetup_rootlogger
def main_only_quicksetup_rootlogger(level: int = logging.DEBUG, with_process_id: bool = False, with_thread_id: bool = False) -> None: """ Quick function to set up the root logger for colour. Should ONLY be called from the ``if __name__...
python
def main_only_quicksetup_rootlogger(level: int = logging.DEBUG, with_process_id: bool = False, with_thread_id: bool = False) -> None: """ Quick function to set up the root logger for colour. Should ONLY be called from the ``if __name__...
[ "def", "main_only_quicksetup_rootlogger", "(", "level", ":", "int", "=", "logging", ".", "DEBUG", ",", "with_process_id", ":", "bool", "=", "False", ",", "with_thread_id", ":", "bool", "=", "False", ")", "->", "None", ":", "# Nasty. Only call from \"if __name__ ==...
Quick function to set up the root logger for colour. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config. Args: level: log level to set with_process_id: include the process ID in the logger's name? with_...
[ "Quick", "function", "to", "set", "up", "the", "root", "logger", "for", "colour", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L209-L227
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
remove_all_logger_handlers
def remove_all_logger_handlers(logger: logging.Logger) -> None: """ Remove all handlers from a logger. Args: logger: logger to modify """ while logger.handlers: h = logger.handlers[0] logger.removeHandler(h)
python
def remove_all_logger_handlers(logger: logging.Logger) -> None: """ Remove all handlers from a logger. Args: logger: logger to modify """ while logger.handlers: h = logger.handlers[0] logger.removeHandler(h)
[ "def", "remove_all_logger_handlers", "(", "logger", ":", "logging", ".", "Logger", ")", "->", "None", ":", "while", "logger", ".", "handlers", ":", "h", "=", "logger", ".", "handlers", "[", "0", "]", "logger", ".", "removeHandler", "(", "h", ")" ]
Remove all handlers from a logger. Args: logger: logger to modify
[ "Remove", "all", "handlers", "from", "a", "logger", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L235-L244
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
reset_logformat
def reset_logformat(logger: logging.Logger, fmt: str, datefmt: str = '%Y-%m-%d %H:%M:%S') -> None: """ Create a new formatter and apply it to the logger. :func:`logging.basicConfig` won't reset the formatter if another module has called it, so always set the form...
python
def reset_logformat(logger: logging.Logger, fmt: str, datefmt: str = '%Y-%m-%d %H:%M:%S') -> None: """ Create a new formatter and apply it to the logger. :func:`logging.basicConfig` won't reset the formatter if another module has called it, so always set the form...
[ "def", "reset_logformat", "(", "logger", ":", "logging", ".", "Logger", ",", "fmt", ":", "str", ",", "datefmt", ":", "str", "=", "'%Y-%m-%d %H:%M:%S'", ")", "->", "None", ":", "handler", "=", "logging", ".", "StreamHandler", "(", ")", "formatter", "=", "...
Create a new formatter and apply it to the logger. :func:`logging.basicConfig` won't reset the formatter if another module has called it, so always set the formatter like this. Args: logger: logger to modify fmt: passed to the ``fmt=`` argument of :class:`logging.Formatter` datefmt...
[ "Create", "a", "new", "formatter", "and", "apply", "it", "to", "the", "logger", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L247-L267
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
reset_logformat_timestamped
def reset_logformat_timestamped(logger: logging.Logger, extraname: str = "", level: int = logging.INFO) -> None: """ Apply a simple time-stamped log format to an existing logger, and set its loglevel to either ``logging.DEBUG`` or ``logging.INF...
python
def reset_logformat_timestamped(logger: logging.Logger, extraname: str = "", level: int = logging.INFO) -> None: """ Apply a simple time-stamped log format to an existing logger, and set its loglevel to either ``logging.DEBUG`` or ``logging.INF...
[ "def", "reset_logformat_timestamped", "(", "logger", ":", "logging", ".", "Logger", ",", "extraname", ":", "str", "=", "\"\"", ",", "level", ":", "int", "=", "logging", ".", "INFO", ")", "->", "None", ":", "namebit", "=", "extraname", "+", "\":\"", "if",...
Apply a simple time-stamped log format to an existing logger, and set its loglevel to either ``logging.DEBUG`` or ``logging.INFO``. Args: logger: logger to modify extraname: additional name to append to the logger's name level: log level to set
[ "Apply", "a", "simple", "time", "-", "stamped", "log", "format", "to", "an", "existing", "logger", "and", "set", "its", "loglevel", "to", "either", "logging", ".", "DEBUG", "or", "logging", ".", "INFO", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L270-L288
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
configure_all_loggers_for_colour
def configure_all_loggers_for_colour(remove_existing: bool = True) -> None: """ Applies a preconfigured datetime/colour scheme to ALL logger. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config. Generally MORE SENSIBLE ...
python
def configure_all_loggers_for_colour(remove_existing: bool = True) -> None: """ Applies a preconfigured datetime/colour scheme to ALL logger. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config. Generally MORE SENSIBLE ...
[ "def", "configure_all_loggers_for_colour", "(", "remove_existing", ":", "bool", "=", "True", ")", "->", "None", ":", "handler", "=", "get_colour_handler", "(", ")", "apply_handler_to_all_logs", "(", "handler", ",", "remove_existing", "=", "remove_existing", ")" ]
Applies a preconfigured datetime/colour scheme to ALL logger. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config. Generally MORE SENSIBLE just to apply a handler to the root logger. Args: remove_existing: remove e...
[ "Applies", "a", "preconfigured", "datetime", "/", "colour", "scheme", "to", "ALL", "logger", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L295-L309
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
apply_handler_to_root_log
def apply_handler_to_root_log(handler: logging.Handler, remove_existing: bool = False) -> None: """ Applies a handler to all logs, optionally removing existing handlers. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/...
python
def apply_handler_to_root_log(handler: logging.Handler, remove_existing: bool = False) -> None: """ Applies a handler to all logs, optionally removing existing handlers. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/...
[ "def", "apply_handler_to_root_log", "(", "handler", ":", "logging", ".", "Handler", ",", "remove_existing", ":", "bool", "=", "False", ")", "->", "None", ":", "rootlog", "=", "logging", ".", "getLogger", "(", ")", "if", "remove_existing", ":", "rootlog", "."...
Applies a handler to all logs, optionally removing existing handlers. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config. Generally MORE SENSIBLE just to apply a handler to the root logger. Args: handler: the hand...
[ "Applies", "a", "handler", "to", "all", "logs", "optionally", "removing", "existing", "handlers", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L312-L329
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
apply_handler_to_all_logs
def apply_handler_to_all_logs(handler: logging.Handler, remove_existing: bool = False) -> None: """ Applies a handler to all logs, optionally removing existing handlers. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/...
python
def apply_handler_to_all_logs(handler: logging.Handler, remove_existing: bool = False) -> None: """ Applies a handler to all logs, optionally removing existing handlers. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/...
[ "def", "apply_handler_to_all_logs", "(", "handler", ":", "logging", ".", "Handler", ",", "remove_existing", ":", "bool", "=", "False", ")", "->", "None", ":", "# noinspection PyUnresolvedReferences", "for", "name", ",", "obj", "in", "logging", ".", "Logger", "."...
Applies a handler to all logs, optionally removing existing handlers. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config. Generally MORE SENSIBLE just to apply a handler to the root logger. Args: handler: the hand...
[ "Applies", "a", "handler", "to", "all", "logs", "optionally", "removing", "existing", "handlers", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L332-L350
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
copy_root_log_to_file
def copy_root_log_to_file(filename: str, fmt: str = LOG_FORMAT, datefmt: str = LOG_DATEFMT) -> None: """ Copy all currently configured logs to the specified file. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python...
python
def copy_root_log_to_file(filename: str, fmt: str = LOG_FORMAT, datefmt: str = LOG_DATEFMT) -> None: """ Copy all currently configured logs to the specified file. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python...
[ "def", "copy_root_log_to_file", "(", "filename", ":", "str", ",", "fmt", ":", "str", "=", "LOG_FORMAT", ",", "datefmt", ":", "str", "=", "LOG_DATEFMT", ")", "->", "None", ":", "fh", "=", "logging", ".", "FileHandler", "(", "filename", ")", "# default file ...
Copy all currently configured logs to the specified file. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config.
[ "Copy", "all", "currently", "configured", "logs", "to", "the", "specified", "file", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L353-L366
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
copy_all_logs_to_file
def copy_all_logs_to_file(filename: str, fmt: str = LOG_FORMAT, datefmt: str = LOG_DATEFMT) -> None: """ Copy all currently configured logs to the specified file. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python...
python
def copy_all_logs_to_file(filename: str, fmt: str = LOG_FORMAT, datefmt: str = LOG_DATEFMT) -> None: """ Copy all currently configured logs to the specified file. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python...
[ "def", "copy_all_logs_to_file", "(", "filename", ":", "str", ",", "fmt", ":", "str", "=", "LOG_FORMAT", ",", "datefmt", ":", "str", "=", "LOG_DATEFMT", ")", "->", "None", ":", "fh", "=", "logging", ".", "FileHandler", "(", "filename", ")", "# default file ...
Copy all currently configured logs to the specified file. Should ONLY be called from the ``if __name__ == 'main'`` script; see https://docs.python.org/3.4/howto/logging.html#library-config. Args: filename: file to send log output to fmt: passed to the ``fmt=`` argument of :class:`logging.F...
[ "Copy", "all", "currently", "configured", "logs", "to", "the", "specified", "file", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L369-L388
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
get_formatter_report
def get_formatter_report(f: logging.Formatter) -> Optional[Dict[str, str]]: """ Returns information on a log formatter, as a dictionary. For debugging. """ if f is None: return None return { '_fmt': f._fmt, 'datefmt': f.datefmt, '_style': str(f._style), }
python
def get_formatter_report(f: logging.Formatter) -> Optional[Dict[str, str]]: """ Returns information on a log formatter, as a dictionary. For debugging. """ if f is None: return None return { '_fmt': f._fmt, 'datefmt': f.datefmt, '_style': str(f._style), }
[ "def", "get_formatter_report", "(", "f", ":", "logging", ".", "Formatter", ")", "->", "Optional", "[", "Dict", "[", "str", ",", "str", "]", "]", ":", "if", "f", "is", "None", ":", "return", "None", "return", "{", "'_fmt'", ":", "f", ".", "_fmt", ",...
Returns information on a log formatter, as a dictionary. For debugging.
[ "Returns", "information", "on", "a", "log", "formatter", "as", "a", "dictionary", ".", "For", "debugging", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L392-L403
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
get_handler_report
def get_handler_report(h: logging.Handler) -> Dict[str, Any]: """ Returns information on a log handler, as a dictionary. For debugging. """ return { 'get_name()': h.get_name(), 'level': h.level, 'formatter': get_formatter_report(h.formatter), 'filters': h.filters, ...
python
def get_handler_report(h: logging.Handler) -> Dict[str, Any]: """ Returns information on a log handler, as a dictionary. For debugging. """ return { 'get_name()': h.get_name(), 'level': h.level, 'formatter': get_formatter_report(h.formatter), 'filters': h.filters, ...
[ "def", "get_handler_report", "(", "h", ":", "logging", ".", "Handler", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "return", "{", "'get_name()'", ":", "h", ".", "get_name", "(", ")", ",", "'level'", ":", "h", ".", "level", ",", "'formatter'"...
Returns information on a log handler, as a dictionary. For debugging.
[ "Returns", "information", "on", "a", "log", "handler", "as", "a", "dictionary", ".", "For", "debugging", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L406-L416
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
get_log_report
def get_log_report(log: Union[logging.Logger, logging.PlaceHolder]) -> Dict[str, Any]: """ Returns information on a log, as a dictionary. For debugging. """ if isinstance(log, logging.Logger): # suppress invalid error for Logger.manager: # noinspection PyUnr...
python
def get_log_report(log: Union[logging.Logger, logging.PlaceHolder]) -> Dict[str, Any]: """ Returns information on a log, as a dictionary. For debugging. """ if isinstance(log, logging.Logger): # suppress invalid error for Logger.manager: # noinspection PyUnr...
[ "def", "get_log_report", "(", "log", ":", "Union", "[", "logging", ".", "Logger", ",", "logging", ".", "PlaceHolder", "]", ")", "->", "Dict", "[", "str", ",", "Any", "]", ":", "if", "isinstance", "(", "log", ",", "logging", ".", "Logger", ")", ":", ...
Returns information on a log, as a dictionary. For debugging.
[ "Returns", "information", "on", "a", "log", "as", "a", "dictionary", ".", "For", "debugging", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L419-L441
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
print_report_on_all_logs
def print_report_on_all_logs() -> None: """ Use :func:`print` to report information on all logs. """ d = {} # noinspection PyUnresolvedReferences for name, obj in logging.Logger.manager.loggerDict.items(): d[name] = get_log_report(obj) rootlogger = logging.getLogger() d['(root lo...
python
def print_report_on_all_logs() -> None: """ Use :func:`print` to report information on all logs. """ d = {} # noinspection PyUnresolvedReferences for name, obj in logging.Logger.manager.loggerDict.items(): d[name] = get_log_report(obj) rootlogger = logging.getLogger() d['(root lo...
[ "def", "print_report_on_all_logs", "(", ")", "->", "None", ":", "d", "=", "{", "}", "# noinspection PyUnresolvedReferences", "for", "name", ",", "obj", "in", "logging", ".", "Logger", ".", "manager", ".", "loggerDict", ".", "items", "(", ")", ":", "d", "["...
Use :func:`print` to report information on all logs.
[ "Use", ":", "func", ":", "print", "to", "report", "information", "on", "all", "logs", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L444-L454
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
set_level_for_logger_and_its_handlers
def set_level_for_logger_and_its_handlers(log: logging.Logger, level: int) -> None: """ Set a log level for a log and all its handlers. Args: log: log to modify level: log level to set """ log.setLevel(level) for h in log.handlers: # ty...
python
def set_level_for_logger_and_its_handlers(log: logging.Logger, level: int) -> None: """ Set a log level for a log and all its handlers. Args: log: log to modify level: log level to set """ log.setLevel(level) for h in log.handlers: # ty...
[ "def", "set_level_for_logger_and_its_handlers", "(", "log", ":", "logging", ".", "Logger", ",", "level", ":", "int", ")", "->", "None", ":", "log", ".", "setLevel", "(", "level", ")", "for", "h", "in", "log", ".", "handlers", ":", "# type: logging.Handler", ...
Set a log level for a log and all its handlers. Args: log: log to modify level: log level to set
[ "Set", "a", "log", "level", "for", "a", "log", "and", "all", "its", "handlers", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L457-L468
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
get_brace_style_log_with_null_handler
def get_brace_style_log_with_null_handler(name: str) -> BraceStyleAdapter: """ For use by library functions. Returns a log with the specifed name that has a null handler attached, and a :class:`BraceStyleAdapter`. """ log = logging.getLogger(name) log.addHandler(logging.NullHandler()) return...
python
def get_brace_style_log_with_null_handler(name: str) -> BraceStyleAdapter: """ For use by library functions. Returns a log with the specifed name that has a null handler attached, and a :class:`BraceStyleAdapter`. """ log = logging.getLogger(name) log.addHandler(logging.NullHandler()) return...
[ "def", "get_brace_style_log_with_null_handler", "(", "name", ":", "str", ")", "->", "BraceStyleAdapter", ":", "log", "=", "logging", ".", "getLogger", "(", "name", ")", "log", ".", "addHandler", "(", "logging", ".", "NullHandler", "(", ")", ")", "return", "B...
For use by library functions. Returns a log with the specifed name that has a null handler attached, and a :class:`BraceStyleAdapter`.
[ "For", "use", "by", "library", "functions", ".", "Returns", "a", "log", "with", "the", "specifed", "name", "that", "has", "a", "null", "handler", "attached", "and", "a", ":", "class", ":", "BraceStyleAdapter", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L697-L704
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
HtmlColorFormatter.format
def format(self, record: logging.LogRecord) -> str: """ Internal function to format the :class:`LogRecord` as HTML. See https://docs.python.org/3.4/library/logging.html#logging.LogRecord """ # message = super().format(record) super().format(record) # Since fmt d...
python
def format(self, record: logging.LogRecord) -> str: """ Internal function to format the :class:`LogRecord` as HTML. See https://docs.python.org/3.4/library/logging.html#logging.LogRecord """ # message = super().format(record) super().format(record) # Since fmt d...
[ "def", "format", "(", "self", ",", "record", ":", "logging", ".", "LogRecord", ")", "->", "str", ":", "# message = super().format(record)", "super", "(", ")", ".", "format", "(", "record", ")", "# Since fmt does not contain asctime, the Formatter.format()", "# will no...
Internal function to format the :class:`LogRecord` as HTML. See https://docs.python.org/3.4/library/logging.html#logging.LogRecord
[ "Internal", "function", "to", "format", "the", ":", "class", ":", "LogRecord", "as", "HTML", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L511-L544
RudolfCardinal/pythonlib
cardinal_pythonlib/logs.py
HtmlColorHandler.emit
def emit(self, record: logging.LogRecord) -> None: """ Internal function to process a :class:`LogRecord`. """ # noinspection PyBroadException try: html = self.format(record) self.logfunction(html) except: # nopep8 self.handleError(reco...
python
def emit(self, record: logging.LogRecord) -> None: """ Internal function to process a :class:`LogRecord`. """ # noinspection PyBroadException try: html = self.format(record) self.logfunction(html) except: # nopep8 self.handleError(reco...
[ "def", "emit", "(", "self", ",", "record", ":", "logging", ".", "LogRecord", ")", "->", "None", ":", "# noinspection PyBroadException", "try", ":", "html", "=", "self", ".", "format", "(", "record", ")", "self", ".", "logfunction", "(", "html", ")", "exc...
Internal function to process a :class:`LogRecord`.
[ "Internal", "function", "to", "process", "a", ":", "class", ":", "LogRecord", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/logs.py#L563-L572
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_table_names
def get_table_names(engine: Engine) -> List[str]: """ Returns a list of database table names from the :class:`Engine`. """ insp = Inspector.from_engine(engine) return insp.get_table_names()
python
def get_table_names(engine: Engine) -> List[str]: """ Returns a list of database table names from the :class:`Engine`. """ insp = Inspector.from_engine(engine) return insp.get_table_names()
[ "def", "get_table_names", "(", "engine", ":", "Engine", ")", "->", "List", "[", "str", "]", ":", "insp", "=", "Inspector", ".", "from_engine", "(", "engine", ")", "return", "insp", ".", "get_table_names", "(", ")" ]
Returns a list of database table names from the :class:`Engine`.
[ "Returns", "a", "list", "of", "database", "table", "names", "from", "the", ":", "class", ":", "Engine", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L71-L76
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_view_names
def get_view_names(engine: Engine) -> List[str]: """ Returns a list of database view names from the :class:`Engine`. """ insp = Inspector.from_engine(engine) return insp.get_view_names()
python
def get_view_names(engine: Engine) -> List[str]: """ Returns a list of database view names from the :class:`Engine`. """ insp = Inspector.from_engine(engine) return insp.get_view_names()
[ "def", "get_view_names", "(", "engine", ":", "Engine", ")", "->", "List", "[", "str", "]", ":", "insp", "=", "Inspector", ".", "from_engine", "(", "engine", ")", "return", "insp", ".", "get_view_names", "(", ")" ]
Returns a list of database view names from the :class:`Engine`.
[ "Returns", "a", "list", "of", "database", "view", "names", "from", "the", ":", "class", ":", "Engine", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L79-L84
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
table_or_view_exists
def table_or_view_exists(engine: Engine, table_or_view_name: str) -> bool: """ Does the named table/view exist (either as a table or as a view) in the database? """ tables_and_views = get_table_names(engine) + get_view_names(engine) return table_or_view_name in tables_and_views
python
def table_or_view_exists(engine: Engine, table_or_view_name: str) -> bool: """ Does the named table/view exist (either as a table or as a view) in the database? """ tables_and_views = get_table_names(engine) + get_view_names(engine) return table_or_view_name in tables_and_views
[ "def", "table_or_view_exists", "(", "engine", ":", "Engine", ",", "table_or_view_name", ":", "str", ")", "->", "bool", ":", "tables_and_views", "=", "get_table_names", "(", "engine", ")", "+", "get_view_names", "(", "engine", ")", "return", "table_or_view_name", ...
Does the named table/view exist (either as a table or as a view) in the database?
[ "Does", "the", "named", "table", "/", "view", "exist", "(", "either", "as", "a", "table", "or", "as", "a", "view", ")", "in", "the", "database?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L101-L107
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
gen_columns_info
def gen_columns_info(engine: Engine, tablename: str) -> Generator[SqlaColumnInspectionInfo, None, None]: """ For the specified table, generate column information as :class:`SqlaColumnInspectionInfo` objects. """ # Dictionary stru...
python
def gen_columns_info(engine: Engine, tablename: str) -> Generator[SqlaColumnInspectionInfo, None, None]: """ For the specified table, generate column information as :class:`SqlaColumnInspectionInfo` objects. """ # Dictionary stru...
[ "def", "gen_columns_info", "(", "engine", ":", "Engine", ",", "tablename", ":", "str", ")", "->", "Generator", "[", "SqlaColumnInspectionInfo", ",", "None", ",", "None", "]", ":", "# Dictionary structure: see", "# http://docs.sqlalchemy.org/en/latest/core/reflection.html#...
For the specified table, generate column information as :class:`SqlaColumnInspectionInfo` objects.
[ "For", "the", "specified", "table", "generate", "column", "information", "as", ":", "class", ":", "SqlaColumnInspectionInfo", "objects", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L136-L147
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_column_info
def get_column_info(engine: Engine, tablename: str, columnname: str) -> Optional[SqlaColumnInspectionInfo]: """ For the specified column in the specified table, get column information as a :class:`SqlaColumnInspectionInfo` object (or ``None`` if such a column can't be found). """...
python
def get_column_info(engine: Engine, tablename: str, columnname: str) -> Optional[SqlaColumnInspectionInfo]: """ For the specified column in the specified table, get column information as a :class:`SqlaColumnInspectionInfo` object (or ``None`` if such a column can't be found). """...
[ "def", "get_column_info", "(", "engine", ":", "Engine", ",", "tablename", ":", "str", ",", "columnname", ":", "str", ")", "->", "Optional", "[", "SqlaColumnInspectionInfo", "]", ":", "for", "info", "in", "gen_columns_info", "(", "engine", ",", "tablename", "...
For the specified column in the specified table, get column information as a :class:`SqlaColumnInspectionInfo` object (or ``None`` if such a column can't be found).
[ "For", "the", "specified", "column", "in", "the", "specified", "table", "get", "column", "information", "as", "a", ":", "class", ":", "SqlaColumnInspectionInfo", "object", "(", "or", "None", "if", "such", "a", "column", "can", "t", "be", "found", ")", "." ...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L150-L160
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_column_type
def get_column_type(engine: Engine, tablename: str, columnname: str) -> Optional[TypeEngine]: """ For the specified column in the specified table, get its type as an instance of an SQLAlchemy column type class (or ``None`` if such a column can't be found). For more on :class:`Ty...
python
def get_column_type(engine: Engine, tablename: str, columnname: str) -> Optional[TypeEngine]: """ For the specified column in the specified table, get its type as an instance of an SQLAlchemy column type class (or ``None`` if such a column can't be found). For more on :class:`Ty...
[ "def", "get_column_type", "(", "engine", ":", "Engine", ",", "tablename", ":", "str", ",", "columnname", ":", "str", ")", "->", "Optional", "[", "TypeEngine", "]", ":", "for", "info", "in", "gen_columns_info", "(", "engine", ",", "tablename", ")", ":", "...
For the specified column in the specified table, get its type as an instance of an SQLAlchemy column type class (or ``None`` if such a column can't be found). For more on :class:`TypeEngine`, see :func:`cardinal_pythonlib.orm_inspect.coltype_as_typeengine`.
[ "For", "the", "specified", "column", "in", "the", "specified", "table", "get", "its", "type", "as", "an", "instance", "of", "an", "SQLAlchemy", "column", "type", "class", "(", "or", "None", "if", "such", "a", "column", "can", "t", "be", "found", ")", "...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L163-L176
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_column_names
def get_column_names(engine: Engine, tablename: str) -> List[str]: """ Get all the database column names for the specified table. """ return [info.name for info in gen_columns_info(engine, tablename)]
python
def get_column_names(engine: Engine, tablename: str) -> List[str]: """ Get all the database column names for the specified table. """ return [info.name for info in gen_columns_info(engine, tablename)]
[ "def", "get_column_names", "(", "engine", ":", "Engine", ",", "tablename", ":", "str", ")", "->", "List", "[", "str", "]", ":", "return", "[", "info", ".", "name", "for", "info", "in", "gen_columns_info", "(", "engine", ",", "tablename", ")", "]" ]
Get all the database column names for the specified table.
[ "Get", "all", "the", "database", "column", "names", "for", "the", "specified", "table", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L179-L183
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_pk_colnames
def get_pk_colnames(table_: Table) -> List[str]: """ If a table has a PK, this will return its database column name(s); otherwise, ``None``. """ pk_names = [] # type: List[str] for col in table_.columns: if col.primary_key: pk_names.append(col.name) return pk_names
python
def get_pk_colnames(table_: Table) -> List[str]: """ If a table has a PK, this will return its database column name(s); otherwise, ``None``. """ pk_names = [] # type: List[str] for col in table_.columns: if col.primary_key: pk_names.append(col.name) return pk_names
[ "def", "get_pk_colnames", "(", "table_", ":", "Table", ")", "->", "List", "[", "str", "]", ":", "pk_names", "=", "[", "]", "# type: List[str]", "for", "col", "in", "table_", ".", "columns", ":", "if", "col", ".", "primary_key", ":", "pk_names", ".", "a...
If a table has a PK, this will return its database column name(s); otherwise, ``None``.
[ "If", "a", "table", "has", "a", "PK", "this", "will", "return", "its", "database", "column", "name", "(", "s", ")", ";", "otherwise", "None", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L190-L199
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_single_int_pk_colname
def get_single_int_pk_colname(table_: Table) -> Optional[str]: """ If a table has a single-field (non-composite) integer PK, this will return its database column name; otherwise, None. Note that it is legitimate for a database table to have both a composite primary key and a separate ``IDENTITY`` (...
python
def get_single_int_pk_colname(table_: Table) -> Optional[str]: """ If a table has a single-field (non-composite) integer PK, this will return its database column name; otherwise, None. Note that it is legitimate for a database table to have both a composite primary key and a separate ``IDENTITY`` (...
[ "def", "get_single_int_pk_colname", "(", "table_", ":", "Table", ")", "->", "Optional", "[", "str", "]", ":", "n_pks", "=", "0", "int_pk_names", "=", "[", "]", "for", "col", "in", "table_", ".", "columns", ":", "if", "col", ".", "primary_key", ":", "n_...
If a table has a single-field (non-composite) integer PK, this will return its database column name; otherwise, None. Note that it is legitimate for a database table to have both a composite primary key and a separate ``IDENTITY`` (``AUTOINCREMENT``) integer field. This function won't find such columns...
[ "If", "a", "table", "has", "a", "single", "-", "field", "(", "non", "-", "composite", ")", "integer", "PK", "this", "will", "return", "its", "database", "column", "name", ";", "otherwise", "None", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L202-L220
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_single_int_autoincrement_colname
def get_single_int_autoincrement_colname(table_: Table) -> Optional[str]: """ If a table has a single integer ``AUTOINCREMENT`` column, this will return its name; otherwise, ``None``. - It's unlikely that a database has >1 ``AUTOINCREMENT`` field anyway, but we should check. - SQL Server's ``...
python
def get_single_int_autoincrement_colname(table_: Table) -> Optional[str]: """ If a table has a single integer ``AUTOINCREMENT`` column, this will return its name; otherwise, ``None``. - It's unlikely that a database has >1 ``AUTOINCREMENT`` field anyway, but we should check. - SQL Server's ``...
[ "def", "get_single_int_autoincrement_colname", "(", "table_", ":", "Table", ")", "->", "Optional", "[", "str", "]", ":", "n_autoinc", "=", "0", "int_autoinc_names", "=", "[", "]", "for", "col", "in", "table_", ".", "columns", ":", "if", "col", ".", "autoin...
If a table has a single integer ``AUTOINCREMENT`` column, this will return its name; otherwise, ``None``. - It's unlikely that a database has >1 ``AUTOINCREMENT`` field anyway, but we should check. - SQL Server's ``IDENTITY`` keyword is equivalent to MySQL's ``AUTOINCREMENT``. - Verify agai...
[ "If", "a", "table", "has", "a", "single", "integer", "AUTOINCREMENT", "column", "this", "will", "return", "its", "name", ";", "otherwise", "None", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L223-L266
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
index_exists
def index_exists(engine: Engine, tablename: str, indexname: str) -> bool: """ Does the specified index exist for the specified table? """ insp = Inspector.from_engine(engine) return any(i['name'] == indexname for i in insp.get_indexes(tablename))
python
def index_exists(engine: Engine, tablename: str, indexname: str) -> bool: """ Does the specified index exist for the specified table? """ insp = Inspector.from_engine(engine) return any(i['name'] == indexname for i in insp.get_indexes(tablename))
[ "def", "index_exists", "(", "engine", ":", "Engine", ",", "tablename", ":", "str", ",", "indexname", ":", "str", ")", "->", "bool", ":", "insp", "=", "Inspector", ".", "from_engine", "(", "engine", ")", "return", "any", "(", "i", "[", "'name'", "]", ...
Does the specified index exist for the specified table?
[ "Does", "the", "specified", "index", "exist", "for", "the", "specified", "table?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L285-L290
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
mssql_get_pk_index_name
def mssql_get_pk_index_name(engine: Engine, tablename: str, schemaname: str = MSSQL_DEFAULT_SCHEMA) -> str: """ For Microsoft SQL Server specifically: fetch the name of the PK index for the specified table (in the specified schema), or ``''`` if none i...
python
def mssql_get_pk_index_name(engine: Engine, tablename: str, schemaname: str = MSSQL_DEFAULT_SCHEMA) -> str: """ For Microsoft SQL Server specifically: fetch the name of the PK index for the specified table (in the specified schema), or ``''`` if none i...
[ "def", "mssql_get_pk_index_name", "(", "engine", ":", "Engine", ",", "tablename", ":", "str", ",", "schemaname", ":", "str", "=", "MSSQL_DEFAULT_SCHEMA", ")", "->", "str", ":", "# http://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.Connection.execute ...
For Microsoft SQL Server specifically: fetch the name of the PK index for the specified table (in the specified schema), or ``''`` if none is found.
[ "For", "Microsoft", "SQL", "Server", "specifically", ":", "fetch", "the", "name", "of", "the", "PK", "index", "for", "the", "specified", "table", "(", "in", "the", "specified", "schema", ")", "or", "if", "none", "is", "found", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L293-L323
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
mssql_transaction_count
def mssql_transaction_count(engine_or_conn: Union[Connection, Engine]) -> int: """ For Microsoft SQL Server specifically: fetch the value of the ``TRANCOUNT`` variable (see e.g. https://docs.microsoft.com/en-us/sql/t-sql/functions/trancount-transact-sql?view=sql-server-2017). Returns ``None`` if it ...
python
def mssql_transaction_count(engine_or_conn: Union[Connection, Engine]) -> int: """ For Microsoft SQL Server specifically: fetch the value of the ``TRANCOUNT`` variable (see e.g. https://docs.microsoft.com/en-us/sql/t-sql/functions/trancount-transact-sql?view=sql-server-2017). Returns ``None`` if it ...
[ "def", "mssql_transaction_count", "(", "engine_or_conn", ":", "Union", "[", "Connection", ",", "Engine", "]", ")", "->", "int", ":", "sql", "=", "\"SELECT @@TRANCOUNT\"", "with", "contextlib", ".", "closing", "(", "engine_or_conn", ".", "execute", "(", "sql", ...
For Microsoft SQL Server specifically: fetch the value of the ``TRANCOUNT`` variable (see e.g. https://docs.microsoft.com/en-us/sql/t-sql/functions/trancount-transact-sql?view=sql-server-2017). Returns ``None`` if it can't be found (unlikely?).
[ "For", "Microsoft", "SQL", "Server", "specifically", ":", "fetch", "the", "value", "of", "the", "TRANCOUNT", "variable", "(", "see", "e", ".", "g", ".", "https", ":", "//", "docs", ".", "microsoft", ".", "com", "/", "en", "-", "us", "/", "sql", "/", ...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L354-L365
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
add_index
def add_index(engine: Engine, sqla_column: Column = None, multiple_sqla_columns: List[Column] = None, unique: bool = False, fulltext: bool = False, length: int = None) -> None: """ Adds an index to a database column (or, in restricted circums...
python
def add_index(engine: Engine, sqla_column: Column = None, multiple_sqla_columns: List[Column] = None, unique: bool = False, fulltext: bool = False, length: int = None) -> None: """ Adds an index to a database column (or, in restricted circums...
[ "def", "add_index", "(", "engine", ":", "Engine", ",", "sqla_column", ":", "Column", "=", "None", ",", "multiple_sqla_columns", ":", "List", "[", "Column", "]", "=", "None", ",", "unique", ":", "bool", "=", "False", ",", "fulltext", ":", "bool", "=", "...
Adds an index to a database column (or, in restricted circumstances, several columns). The table name is worked out from the :class:`Column` object. Args: engine: SQLAlchemy :class:`Engine` object sqla_column: single column to index multiple_sqla_columns: multiple columns to index ...
[ "Adds", "an", "index", "to", "a", "database", "column", "(", "or", "in", "restricted", "circumstances", "several", "columns", ")", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L368-L530
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
make_bigint_autoincrement_column
def make_bigint_autoincrement_column(column_name: str, dialect: Dialect) -> Column: """ Returns an instance of :class:`Column` representing a :class:`BigInteger` ``AUTOINCREMENT`` column in the specified :class:`Dialect`. """ # noinspection PyUnresolvedReferences...
python
def make_bigint_autoincrement_column(column_name: str, dialect: Dialect) -> Column: """ Returns an instance of :class:`Column` representing a :class:`BigInteger` ``AUTOINCREMENT`` column in the specified :class:`Dialect`. """ # noinspection PyUnresolvedReferences...
[ "def", "make_bigint_autoincrement_column", "(", "column_name", ":", "str", ",", "dialect", ":", "Dialect", ")", "->", "Column", ":", "# noinspection PyUnresolvedReferences", "if", "dialect", ".", "name", "==", "SqlaDialectName", ".", "MSSQL", ":", "return", "Column"...
Returns an instance of :class:`Column` representing a :class:`BigInteger` ``AUTOINCREMENT`` column in the specified :class:`Dialect`.
[ "Returns", "an", "instance", "of", ":", "class", ":", "Column", "representing", "a", ":", "class", ":", "BigInteger", "AUTOINCREMENT", "column", "in", "the", "specified", ":", "class", ":", "Dialect", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L538-L553
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
column_creation_ddl
def column_creation_ddl(sqla_column: Column, dialect: Dialect) -> str: """ Returns DDL to create a column, using the specified dialect. The column should already be bound to a table (because e.g. the SQL Server dialect requires this for DDL generation). Manual testing: .. code-block:: pyt...
python
def column_creation_ddl(sqla_column: Column, dialect: Dialect) -> str: """ Returns DDL to create a column, using the specified dialect. The column should already be bound to a table (because e.g. the SQL Server dialect requires this for DDL generation). Manual testing: .. code-block:: pyt...
[ "def", "column_creation_ddl", "(", "sqla_column", ":", "Column", ",", "dialect", ":", "Dialect", ")", "->", "str", ":", "# noqa", "return", "str", "(", "CreateColumn", "(", "sqla_column", ")", ".", "compile", "(", "dialect", "=", "dialect", ")", ")" ]
Returns DDL to create a column, using the specified dialect. The column should already be bound to a table (because e.g. the SQL Server dialect requires this for DDL generation). Manual testing: .. code-block:: python from sqlalchemy.schema import Column, CreateColumn, MetaData, Sequence...
[ "Returns", "DDL", "to", "create", "a", "column", "using", "the", "specified", "dialect", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L557-L591
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
giant_text_sqltype
def giant_text_sqltype(dialect: Dialect) -> str: """ Returns the SQL column type used to make very large text columns for a given dialect. Args: dialect: a SQLAlchemy :class:`Dialect` Returns: the SQL data type of "giant text", typically 'LONGTEXT' for MySQL and 'NVARCHAR(MA...
python
def giant_text_sqltype(dialect: Dialect) -> str: """ Returns the SQL column type used to make very large text columns for a given dialect. Args: dialect: a SQLAlchemy :class:`Dialect` Returns: the SQL data type of "giant text", typically 'LONGTEXT' for MySQL and 'NVARCHAR(MA...
[ "def", "giant_text_sqltype", "(", "dialect", ":", "Dialect", ")", "->", "str", ":", "if", "dialect", ".", "name", "==", "SqlaDialectName", ".", "SQLSERVER", ":", "return", "'NVARCHAR(MAX)'", "elif", "dialect", ".", "name", "==", "SqlaDialectName", ".", "MYSQL"...
Returns the SQL column type used to make very large text columns for a given dialect. Args: dialect: a SQLAlchemy :class:`Dialect` Returns: the SQL data type of "giant text", typically 'LONGTEXT' for MySQL and 'NVARCHAR(MAX)' for SQL Server.
[ "Returns", "the", "SQL", "column", "type", "used", "to", "make", "very", "large", "text", "columns", "for", "a", "given", "dialect", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L595-L611
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
_get_sqla_coltype_class_from_str
def _get_sqla_coltype_class_from_str(coltype: str, dialect: Dialect) -> Type[TypeEngine]: """ Returns the SQLAlchemy class corresponding to a particular SQL column type in a given dialect. Performs an upper- and lower-case search. For example, the SQLite dialect...
python
def _get_sqla_coltype_class_from_str(coltype: str, dialect: Dialect) -> Type[TypeEngine]: """ Returns the SQLAlchemy class corresponding to a particular SQL column type in a given dialect. Performs an upper- and lower-case search. For example, the SQLite dialect...
[ "def", "_get_sqla_coltype_class_from_str", "(", "coltype", ":", "str", ",", "dialect", ":", "Dialect", ")", "->", "Type", "[", "TypeEngine", "]", ":", "# noinspection PyUnresolvedReferences", "ischema_names", "=", "dialect", ".", "ischema_names", "try", ":", "return...
Returns the SQLAlchemy class corresponding to a particular SQL column type in a given dialect. Performs an upper- and lower-case search. For example, the SQLite dialect uses upper case, and the MySQL dialect uses lower case.
[ "Returns", "the", "SQLAlchemy", "class", "corresponding", "to", "a", "particular", "SQL", "column", "type", "in", "a", "given", "dialect", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L632-L647
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_list_of_sql_string_literals_from_quoted_csv
def get_list_of_sql_string_literals_from_quoted_csv(x: str) -> List[str]: """ Used to extract SQL column type parameters. For example, MySQL has column types that look like ``ENUM('a', 'b', 'c', 'd')``. This function takes the ``"'a', 'b', 'c', 'd'"`` and converts it to ``['a', 'b', 'c', 'd']``. """...
python
def get_list_of_sql_string_literals_from_quoted_csv(x: str) -> List[str]: """ Used to extract SQL column type parameters. For example, MySQL has column types that look like ``ENUM('a', 'b', 'c', 'd')``. This function takes the ``"'a', 'b', 'c', 'd'"`` and converts it to ``['a', 'b', 'c', 'd']``. """...
[ "def", "get_list_of_sql_string_literals_from_quoted_csv", "(", "x", ":", "str", ")", "->", "List", "[", "str", "]", ":", "f", "=", "io", ".", "StringIO", "(", "x", ")", "reader", "=", "csv", ".", "reader", "(", "f", ",", "delimiter", "=", "','", ",", ...
Used to extract SQL column type parameters. For example, MySQL has column types that look like ``ENUM('a', 'b', 'c', 'd')``. This function takes the ``"'a', 'b', 'c', 'd'"`` and converts it to ``['a', 'b', 'c', 'd']``.
[ "Used", "to", "extract", "SQL", "column", "type", "parameters", ".", "For", "example", "MySQL", "has", "column", "types", "that", "look", "like", "ENUM", "(", "a", "b", "c", "d", ")", ".", "This", "function", "takes", "the", "a", "b", "c", "d", "and"...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L650-L660
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
get_sqla_coltype_from_dialect_str
def get_sqla_coltype_from_dialect_str(coltype: str, dialect: Dialect) -> TypeEngine: """ Returns an SQLAlchemy column type, given a column type name (a string) and an SQLAlchemy dialect. For example, this might convert the string ``INTEGER(11)`` to an SQLAlchemy ``I...
python
def get_sqla_coltype_from_dialect_str(coltype: str, dialect: Dialect) -> TypeEngine: """ Returns an SQLAlchemy column type, given a column type name (a string) and an SQLAlchemy dialect. For example, this might convert the string ``INTEGER(11)`` to an SQLAlchemy ``I...
[ "def", "get_sqla_coltype_from_dialect_str", "(", "coltype", ":", "str", ",", "dialect", ":", "Dialect", ")", "->", "TypeEngine", ":", "size", "=", "None", "# type: Optional[int]", "dp", "=", "None", "# type: Optional[int]", "args", "=", "[", "]", "# type: List[Any...
Returns an SQLAlchemy column type, given a column type name (a string) and an SQLAlchemy dialect. For example, this might convert the string ``INTEGER(11)`` to an SQLAlchemy ``Integer(length=11)``. Args: dialect: a SQLAlchemy :class:`Dialect` class coltype: a ``str()`` representation, e.g....
[ "Returns", "an", "SQLAlchemy", "column", "type", "given", "a", "column", "type", "name", "(", "a", "string", ")", "and", "an", "SQLAlchemy", "dialect", ".", "For", "example", "this", "might", "convert", "the", "string", "INTEGER", "(", "11", ")", "to", "...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L664-L799
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
remove_collation
def remove_collation(coltype: TypeEngine) -> TypeEngine: """ Returns a copy of the specific column type with any ``COLLATION`` removed. """ if not getattr(coltype, 'collation', None): return coltype newcoltype = copy.copy(coltype) newcoltype.collation = None return newcoltype
python
def remove_collation(coltype: TypeEngine) -> TypeEngine: """ Returns a copy of the specific column type with any ``COLLATION`` removed. """ if not getattr(coltype, 'collation', None): return coltype newcoltype = copy.copy(coltype) newcoltype.collation = None return newcoltype
[ "def", "remove_collation", "(", "coltype", ":", "TypeEngine", ")", "->", "TypeEngine", ":", "if", "not", "getattr", "(", "coltype", ",", "'collation'", ",", "None", ")", ":", "return", "coltype", "newcoltype", "=", "copy", ".", "copy", "(", "coltype", ")",...
Returns a copy of the specific column type with any ``COLLATION`` removed.
[ "Returns", "a", "copy", "of", "the", "specific", "column", "type", "with", "any", "COLLATION", "removed", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L813-L821
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
convert_sqla_type_for_dialect
def convert_sqla_type_for_dialect( coltype: TypeEngine, dialect: Dialect, strip_collation: bool = True, convert_mssql_timestamp: bool = True, expand_for_scrubbing: bool = False) -> TypeEngine: """ Converts an SQLAlchemy column type from one SQL dialect to another. Ar...
python
def convert_sqla_type_for_dialect( coltype: TypeEngine, dialect: Dialect, strip_collation: bool = True, convert_mssql_timestamp: bool = True, expand_for_scrubbing: bool = False) -> TypeEngine: """ Converts an SQLAlchemy column type from one SQL dialect to another. Ar...
[ "def", "convert_sqla_type_for_dialect", "(", "coltype", ":", "TypeEngine", ",", "dialect", ":", "Dialect", ",", "strip_collation", ":", "bool", "=", "True", ",", "convert_mssql_timestamp", ":", "bool", "=", "True", ",", "expand_for_scrubbing", ":", "bool", "=", ...
Converts an SQLAlchemy column type from one SQL dialect to another. Args: coltype: SQLAlchemy column type in the source dialect dialect: destination :class:`Dialect` strip_collation: remove any ``COLLATION`` information? convert_mssql_timestamp: since you cannot write...
[ "Converts", "an", "SQLAlchemy", "column", "type", "from", "one", "SQL", "dialect", "to", "another", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L825-L923
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
_coltype_to_typeengine
def _coltype_to_typeengine(coltype: Union[TypeEngine, VisitableType]) -> TypeEngine: """ An example is simplest: if you pass in ``Integer()`` (an instance of :class:`TypeEngine`), you'll get ``Integer()`` back. If you pass in ``Integer`` (an instance of :class:`...
python
def _coltype_to_typeengine(coltype: Union[TypeEngine, VisitableType]) -> TypeEngine: """ An example is simplest: if you pass in ``Integer()`` (an instance of :class:`TypeEngine`), you'll get ``Integer()`` back. If you pass in ``Integer`` (an instance of :class:`...
[ "def", "_coltype_to_typeengine", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ")", "->", "TypeEngine", ":", "if", "isinstance", "(", "coltype", ",", "VisitableType", ")", ":", "coltype", "=", "coltype", "(", ")", "assert", "isi...
An example is simplest: if you pass in ``Integer()`` (an instance of :class:`TypeEngine`), you'll get ``Integer()`` back. If you pass in ``Integer`` (an instance of :class:`VisitableType`), you'll also get ``Integer()`` back. The function asserts that its return type is an instance of :class:`TypeEngine...
[ "An", "example", "is", "simplest", ":", "if", "you", "pass", "in", "Integer", "()", "(", "an", "instance", "of", ":", "class", ":", "TypeEngine", ")", "you", "ll", "get", "Integer", "()", "back", ".", "If", "you", "pass", "in", "Integer", "(", "an", ...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L941-L953
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
is_sqlatype_binary
def is_sqlatype_binary(coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type a binary type? """ # Several binary types inherit internally from _Binary, making that the # easiest to check. coltype = _coltype_to_typeengine(coltype) # noinspection PyProtectedMemb...
python
def is_sqlatype_binary(coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type a binary type? """ # Several binary types inherit internally from _Binary, making that the # easiest to check. coltype = _coltype_to_typeengine(coltype) # noinspection PyProtectedMemb...
[ "def", "is_sqlatype_binary", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ")", "->", "bool", ":", "# Several binary types inherit internally from _Binary, making that the", "# easiest to check.", "coltype", "=", "_coltype_to_typeengine", "(", ...
Is the SQLAlchemy column type a binary type?
[ "Is", "the", "SQLAlchemy", "column", "type", "a", "binary", "type?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L956-L964
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
is_sqlatype_date
def is_sqlatype_date(coltype: TypeEngine) -> bool: """ Is the SQLAlchemy column type a date type? """ coltype = _coltype_to_typeengine(coltype) # No longer valid in SQLAlchemy 1.2.11: # return isinstance(coltype, sqltypes._DateAffinity) return ( isinstance(coltype, sqltypes.DateTime)...
python
def is_sqlatype_date(coltype: TypeEngine) -> bool: """ Is the SQLAlchemy column type a date type? """ coltype = _coltype_to_typeengine(coltype) # No longer valid in SQLAlchemy 1.2.11: # return isinstance(coltype, sqltypes._DateAffinity) return ( isinstance(coltype, sqltypes.DateTime)...
[ "def", "is_sqlatype_date", "(", "coltype", ":", "TypeEngine", ")", "->", "bool", ":", "coltype", "=", "_coltype_to_typeengine", "(", "coltype", ")", "# No longer valid in SQLAlchemy 1.2.11:", "# return isinstance(coltype, sqltypes._DateAffinity)", "return", "(", "isinstance",...
Is the SQLAlchemy column type a date type?
[ "Is", "the", "SQLAlchemy", "column", "type", "a", "date", "type?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L967-L977
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
is_sqlatype_integer
def is_sqlatype_integer(coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type an integer type? """ coltype = _coltype_to_typeengine(coltype) return isinstance(coltype, sqltypes.Integer)
python
def is_sqlatype_integer(coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type an integer type? """ coltype = _coltype_to_typeengine(coltype) return isinstance(coltype, sqltypes.Integer)
[ "def", "is_sqlatype_integer", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ")", "->", "bool", ":", "coltype", "=", "_coltype_to_typeengine", "(", "coltype", ")", "return", "isinstance", "(", "coltype", ",", "sqltypes", ".", "Inte...
Is the SQLAlchemy column type an integer type?
[ "Is", "the", "SQLAlchemy", "column", "type", "an", "integer", "type?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L980-L985
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
is_sqlatype_numeric
def is_sqlatype_numeric(coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type one that inherits from :class:`Numeric`, such as :class:`Float`, :class:`Decimal`? """ coltype = _coltype_to_typeengine(coltype) return isinstance(coltype, sqltypes.Numeric)
python
def is_sqlatype_numeric(coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type one that inherits from :class:`Numeric`, such as :class:`Float`, :class:`Decimal`? """ coltype = _coltype_to_typeengine(coltype) return isinstance(coltype, sqltypes.Numeric)
[ "def", "is_sqlatype_numeric", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ")", "->", "bool", ":", "coltype", "=", "_coltype_to_typeengine", "(", "coltype", ")", "return", "isinstance", "(", "coltype", ",", "sqltypes", ".", "Nume...
Is the SQLAlchemy column type one that inherits from :class:`Numeric`, such as :class:`Float`, :class:`Decimal`?
[ "Is", "the", "SQLAlchemy", "column", "type", "one", "that", "inherits", "from", ":", "class", ":", "Numeric", "such", "as", ":", "class", ":", "Float", ":", "class", ":", "Decimal", "?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L988-L994
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
is_sqlatype_string
def is_sqlatype_string(coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type a string type? """ coltype = _coltype_to_typeengine(coltype) return isinstance(coltype, sqltypes.String)
python
def is_sqlatype_string(coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type a string type? """ coltype = _coltype_to_typeengine(coltype) return isinstance(coltype, sqltypes.String)
[ "def", "is_sqlatype_string", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ")", "->", "bool", ":", "coltype", "=", "_coltype_to_typeengine", "(", "coltype", ")", "return", "isinstance", "(", "coltype", ",", "sqltypes", ".", "Strin...
Is the SQLAlchemy column type a string type?
[ "Is", "the", "SQLAlchemy", "column", "type", "a", "string", "type?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L997-L1002
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
is_sqlatype_text_of_length_at_least
def is_sqlatype_text_of_length_at_least( coltype: Union[TypeEngine, VisitableType], min_length: int = 1000) -> bool: """ Is the SQLAlchemy column type a string type that's at least the specified length? """ coltype = _coltype_to_typeengine(coltype) if not isinstance(coltype, sqlt...
python
def is_sqlatype_text_of_length_at_least( coltype: Union[TypeEngine, VisitableType], min_length: int = 1000) -> bool: """ Is the SQLAlchemy column type a string type that's at least the specified length? """ coltype = _coltype_to_typeengine(coltype) if not isinstance(coltype, sqlt...
[ "def", "is_sqlatype_text_of_length_at_least", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ",", "min_length", ":", "int", "=", "1000", ")", "->", "bool", ":", "coltype", "=", "_coltype_to_typeengine", "(", "coltype", ")", "if", "...
Is the SQLAlchemy column type a string type that's at least the specified length?
[ "Is", "the", "SQLAlchemy", "column", "type", "a", "string", "type", "that", "s", "at", "least", "the", "specified", "length?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1005-L1017
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
is_sqlatype_text_over_one_char
def is_sqlatype_text_over_one_char( coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type a string type that's more than one character long? """ coltype = _coltype_to_typeengine(coltype) return is_sqlatype_text_of_length_at_least(coltype, 2)
python
def is_sqlatype_text_over_one_char( coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type a string type that's more than one character long? """ coltype = _coltype_to_typeengine(coltype) return is_sqlatype_text_of_length_at_least(coltype, 2)
[ "def", "is_sqlatype_text_over_one_char", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ")", "->", "bool", ":", "coltype", "=", "_coltype_to_typeengine", "(", "coltype", ")", "return", "is_sqlatype_text_of_length_at_least", "(", "coltype",...
Is the SQLAlchemy column type a string type that's more than one character long?
[ "Is", "the", "SQLAlchemy", "column", "type", "a", "string", "type", "that", "s", "more", "than", "one", "character", "long?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1020-L1027
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
does_sqlatype_merit_fulltext_index
def does_sqlatype_merit_fulltext_index( coltype: Union[TypeEngine, VisitableType], min_length: int = 1000) -> bool: """ Is the SQLAlchemy column type a type that might merit a ``FULLTEXT`` index (meaning a string type of at least ``min_length``)? """ coltype = _coltype_to_typeengine(...
python
def does_sqlatype_merit_fulltext_index( coltype: Union[TypeEngine, VisitableType], min_length: int = 1000) -> bool: """ Is the SQLAlchemy column type a type that might merit a ``FULLTEXT`` index (meaning a string type of at least ``min_length``)? """ coltype = _coltype_to_typeengine(...
[ "def", "does_sqlatype_merit_fulltext_index", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ",", "min_length", ":", "int", "=", "1000", ")", "->", "bool", ":", "coltype", "=", "_coltype_to_typeengine", "(", "coltype", ")", "return", ...
Is the SQLAlchemy column type a type that might merit a ``FULLTEXT`` index (meaning a string type of at least ``min_length``)?
[ "Is", "the", "SQLAlchemy", "column", "type", "a", "type", "that", "might", "merit", "a", "FULLTEXT", "index", "(", "meaning", "a", "string", "type", "of", "at", "least", "min_length", ")", "?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1030-L1038
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
does_sqlatype_require_index_len
def does_sqlatype_require_index_len( coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type one that requires its indexes to have a length specified? (MySQL, at least, requires index length to be specified for ``BLOB`` and ``TEXT`` columns: http://dev.mysq...
python
def does_sqlatype_require_index_len( coltype: Union[TypeEngine, VisitableType]) -> bool: """ Is the SQLAlchemy column type one that requires its indexes to have a length specified? (MySQL, at least, requires index length to be specified for ``BLOB`` and ``TEXT`` columns: http://dev.mysq...
[ "def", "does_sqlatype_require_index_len", "(", "coltype", ":", "Union", "[", "TypeEngine", ",", "VisitableType", "]", ")", "->", "bool", ":", "coltype", "=", "_coltype_to_typeengine", "(", "coltype", ")", "if", "isinstance", "(", "coltype", ",", "sqltypes", ".",...
Is the SQLAlchemy column type one that requires its indexes to have a length specified? (MySQL, at least, requires index length to be specified for ``BLOB`` and ``TEXT`` columns: http://dev.mysql.com/doc/refman/5.7/en/create-index.html.)
[ "Is", "the", "SQLAlchemy", "column", "type", "one", "that", "requires", "its", "indexes", "to", "have", "a", "length", "specified?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1041-L1056
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
column_types_equal
def column_types_equal(a_coltype: TypeEngine, b_coltype: TypeEngine) -> bool: """ Checks that two SQLAlchemy column types are equal (by comparing ``str()`` versions of them). See http://stackoverflow.com/questions/34787794/sqlalchemy-column-type-comparison. IMPERFECT. """ # noqa ...
python
def column_types_equal(a_coltype: TypeEngine, b_coltype: TypeEngine) -> bool: """ Checks that two SQLAlchemy column types are equal (by comparing ``str()`` versions of them). See http://stackoverflow.com/questions/34787794/sqlalchemy-column-type-comparison. IMPERFECT. """ # noqa ...
[ "def", "column_types_equal", "(", "a_coltype", ":", "TypeEngine", ",", "b_coltype", ":", "TypeEngine", ")", "->", "bool", ":", "# noqa", "return", "str", "(", "a_coltype", ")", "==", "str", "(", "b_coltype", ")" ]
Checks that two SQLAlchemy column types are equal (by comparing ``str()`` versions of them). See http://stackoverflow.com/questions/34787794/sqlalchemy-column-type-comparison. IMPERFECT.
[ "Checks", "that", "two", "SQLAlchemy", "column", "types", "are", "equal", "(", "by", "comparing", "str", "()", "versions", "of", "them", ")", ".", "See", "http", ":", "//", "stackoverflow", ".", "com", "/", "questions", "/", "34787794", "/", "sqlalchemy", ...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1089-L1098
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
columns_equal
def columns_equal(a: Column, b: Column) -> bool: """ Are two SQLAlchemy columns are equal? Checks based on: - column ``name`` - column ``type`` (see :func:`column_types_equal`) - ``nullable`` """ return ( a.name == b.name and column_types_equal(a.type, b.type) and a....
python
def columns_equal(a: Column, b: Column) -> bool: """ Are two SQLAlchemy columns are equal? Checks based on: - column ``name`` - column ``type`` (see :func:`column_types_equal`) - ``nullable`` """ return ( a.name == b.name and column_types_equal(a.type, b.type) and a....
[ "def", "columns_equal", "(", "a", ":", "Column", ",", "b", ":", "Column", ")", "->", "bool", ":", "return", "(", "a", ".", "name", "==", "b", ".", "name", "and", "column_types_equal", "(", "a", ".", "type", ",", "b", ".", "type", ")", "and", "a",...
Are two SQLAlchemy columns are equal? Checks based on: - column ``name`` - column ``type`` (see :func:`column_types_equal`) - ``nullable``
[ "Are", "two", "SQLAlchemy", "columns", "are", "equal?", "Checks", "based", "on", ":" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1101-L1113
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
column_lists_equal
def column_lists_equal(a: List[Column], b: List[Column]) -> bool: """ Are all columns in list ``a`` equal to their counterparts in list ``b``, as per :func:`columns_equal`? """ n = len(a) if len(b) != n: return False for i in range(n): if not columns_equal(a[i], b[i]): ...
python
def column_lists_equal(a: List[Column], b: List[Column]) -> bool: """ Are all columns in list ``a`` equal to their counterparts in list ``b``, as per :func:`columns_equal`? """ n = len(a) if len(b) != n: return False for i in range(n): if not columns_equal(a[i], b[i]): ...
[ "def", "column_lists_equal", "(", "a", ":", "List", "[", "Column", "]", ",", "b", ":", "List", "[", "Column", "]", ")", "->", "bool", ":", "n", "=", "len", "(", "a", ")", "if", "len", "(", "b", ")", "!=", "n", ":", "return", "False", "for", "...
Are all columns in list ``a`` equal to their counterparts in list ``b``, as per :func:`columns_equal`?
[ "Are", "all", "columns", "in", "list", "a", "equal", "to", "their", "counterparts", "in", "list", "b", "as", "per", ":", "func", ":", "columns_equal", "?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1116-L1128
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
indexes_equal
def indexes_equal(a: Index, b: Index) -> bool: """ Are two indexes equal? Checks by comparing ``str()`` versions of them. (AM UNSURE IF THIS IS ENOUGH.) """ return str(a) == str(b)
python
def indexes_equal(a: Index, b: Index) -> bool: """ Are two indexes equal? Checks by comparing ``str()`` versions of them. (AM UNSURE IF THIS IS ENOUGH.) """ return str(a) == str(b)
[ "def", "indexes_equal", "(", "a", ":", "Index", ",", "b", ":", "Index", ")", "->", "bool", ":", "return", "str", "(", "a", ")", "==", "str", "(", "b", ")" ]
Are two indexes equal? Checks by comparing ``str()`` versions of them. (AM UNSURE IF THIS IS ENOUGH.)
[ "Are", "two", "indexes", "equal?", "Checks", "by", "comparing", "str", "()", "versions", "of", "them", ".", "(", "AM", "UNSURE", "IF", "THIS", "IS", "ENOUGH", ".", ")" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1131-L1136
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/schema.py
index_lists_equal
def index_lists_equal(a: List[Index], b: List[Index]) -> bool: """ Are all indexes in list ``a`` equal to their counterparts in list ``b``, as per :func:`indexes_equal`? """ n = len(a) if len(b) != n: return False for i in range(n): if not indexes_equal(a[i], b[i]): ...
python
def index_lists_equal(a: List[Index], b: List[Index]) -> bool: """ Are all indexes in list ``a`` equal to their counterparts in list ``b``, as per :func:`indexes_equal`? """ n = len(a) if len(b) != n: return False for i in range(n): if not indexes_equal(a[i], b[i]): ...
[ "def", "index_lists_equal", "(", "a", ":", "List", "[", "Index", "]", ",", "b", ":", "List", "[", "Index", "]", ")", "->", "bool", ":", "n", "=", "len", "(", "a", ")", "if", "len", "(", "b", ")", "!=", "n", ":", "return", "False", "for", "i",...
Are all indexes in list ``a`` equal to their counterparts in list ``b``, as per :func:`indexes_equal`?
[ "Are", "all", "indexes", "in", "list", "a", "equal", "to", "their", "counterparts", "in", "list", "b", "as", "per", ":", "func", ":", "indexes_equal", "?" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/schema.py#L1139-L1151
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
to_bytes
def to_bytes(data: Any) -> bytearray: """ Convert anything to a ``bytearray``. See - http://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3 - http://stackoverflow.com/questions/10459067/how-to-convert-my-bytearrayb-x9e-x18k-x9a-to-something-like-this-x9e...
python
def to_bytes(data: Any) -> bytearray: """ Convert anything to a ``bytearray``. See - http://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3 - http://stackoverflow.com/questions/10459067/how-to-convert-my-bytearrayb-x9e-x18k-x9a-to-something-like-this-x9e...
[ "def", "to_bytes", "(", "data", ":", "Any", ")", "->", "bytearray", ":", "# noqa", "if", "isinstance", "(", "data", ",", "int", ")", ":", "return", "bytearray", "(", "[", "data", "]", ")", "return", "bytearray", "(", "data", ",", "encoding", "=", "'l...
Convert anything to a ``bytearray``. See - http://stackoverflow.com/questions/7585435/best-way-to-convert-string-to-bytes-in-python-3 - http://stackoverflow.com/questions/10459067/how-to-convert-my-bytearrayb-x9e-x18k-x9a-to-something-like-this-x9e-x1
[ "Convert", "anything", "to", "a", "bytearray", ".", "See", "-", "http", ":", "//", "stackoverflow", ".", "com", "/", "questions", "/", "7585435", "/", "best", "-", "way", "-", "to", "-", "convert", "-", "string", "-", "to", "-", "bytes", "-", "in", ...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L305-L316
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
signed_to_twos_comp
def signed_to_twos_comp(val: int, n_bits: int) -> int: """ Convert a signed integer to its "two's complement" representation. Args: val: signed integer n_bits: number of bits (which must reflect a whole number of bytes) Returns: unsigned integer: two's complement version "...
python
def signed_to_twos_comp(val: int, n_bits: int) -> int: """ Convert a signed integer to its "two's complement" representation. Args: val: signed integer n_bits: number of bits (which must reflect a whole number of bytes) Returns: unsigned integer: two's complement version "...
[ "def", "signed_to_twos_comp", "(", "val", ":", "int", ",", "n_bits", ":", "int", ")", "->", "int", ":", "assert", "n_bits", "%", "8", "==", "0", ",", "\"Must specify a whole number of bytes\"", "n_bytes", "=", "n_bits", "//", "8", "b", "=", "val", ".", "...
Convert a signed integer to its "two's complement" representation. Args: val: signed integer n_bits: number of bits (which must reflect a whole number of bytes) Returns: unsigned integer: two's complement version
[ "Convert", "a", "signed", "integer", "to", "its", "two", "s", "complement", "representation", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L347-L362
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
bytes_to_long
def bytes_to_long(bytesdata: bytes) -> int: """ Converts an 8-byte sequence to a long integer. Args: bytesdata: 8 consecutive bytes, as a ``bytes`` object, in little-endian format (least significant byte [LSB] first) Returns: integer """ assert len(bytesdata) == 8 ...
python
def bytes_to_long(bytesdata: bytes) -> int: """ Converts an 8-byte sequence to a long integer. Args: bytesdata: 8 consecutive bytes, as a ``bytes`` object, in little-endian format (least significant byte [LSB] first) Returns: integer """ assert len(bytesdata) == 8 ...
[ "def", "bytes_to_long", "(", "bytesdata", ":", "bytes", ")", "->", "int", ":", "assert", "len", "(", "bytesdata", ")", "==", "8", "return", "sum", "(", "(", "b", "<<", "(", "k", "*", "8", ")", "for", "k", ",", "b", "in", "enumerate", "(", "bytesd...
Converts an 8-byte sequence to a long integer. Args: bytesdata: 8 consecutive bytes, as a ``bytes`` object, in little-endian format (least significant byte [LSB] first) Returns: integer
[ "Converts", "an", "8", "-", "byte", "sequence", "to", "a", "long", "integer", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L365-L378
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
murmur3_x86_32
def murmur3_x86_32(data: Union[bytes, bytearray], seed: int = 0) -> int: """ Pure 32-bit Python implementation of MurmurHash3; see http://stackoverflow.com/questions/13305290/is-there-a-pure-python-implementation-of-murmurhash. Args: data: data to hash seed: seed Returns: ...
python
def murmur3_x86_32(data: Union[bytes, bytearray], seed: int = 0) -> int: """ Pure 32-bit Python implementation of MurmurHash3; see http://stackoverflow.com/questions/13305290/is-there-a-pure-python-implementation-of-murmurhash. Args: data: data to hash seed: seed Returns: ...
[ "def", "murmur3_x86_32", "(", "data", ":", "Union", "[", "bytes", ",", "bytearray", "]", ",", "seed", ":", "int", "=", "0", ")", "->", "int", ":", "# noqa", "c1", "=", "0xcc9e2d51", "c2", "=", "0x1b873593", "length", "=", "len", "(", "data", ")", "...
Pure 32-bit Python implementation of MurmurHash3; see http://stackoverflow.com/questions/13305290/is-there-a-pure-python-implementation-of-murmurhash. Args: data: data to hash seed: seed Returns: integer hash
[ "Pure", "32", "-", "bit", "Python", "implementation", "of", "MurmurHash3", ";", "see", "http", ":", "//", "stackoverflow", ".", "com", "/", "questions", "/", "13305290", "/", "is", "-", "there", "-", "a", "-", "pure", "-", "python", "-", "implementation"...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L389-L448
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
murmur3_64
def murmur3_64(data: Union[bytes, bytearray], seed: int = 19820125) -> int: """ Pure 64-bit Python implementation of MurmurHash3; see http://stackoverflow.com/questions/13305290/is-there-a-pure-python-implementation-of-murmurhash (plus RNC bugfixes). Args: data: data to hash s...
python
def murmur3_64(data: Union[bytes, bytearray], seed: int = 19820125) -> int: """ Pure 64-bit Python implementation of MurmurHash3; see http://stackoverflow.com/questions/13305290/is-there-a-pure-python-implementation-of-murmurhash (plus RNC bugfixes). Args: data: data to hash s...
[ "def", "murmur3_64", "(", "data", ":", "Union", "[", "bytes", ",", "bytearray", "]", ",", "seed", ":", "int", "=", "19820125", ")", "->", "int", ":", "# noqa", "m", "=", "0xc6a4a7935bd1e995", "r", "=", "47", "mask", "=", "2", "**", "64", "-", "1", ...
Pure 64-bit Python implementation of MurmurHash3; see http://stackoverflow.com/questions/13305290/is-there-a-pure-python-implementation-of-murmurhash (plus RNC bugfixes). Args: data: data to hash seed: seed Returns: integer hash
[ "Pure", "64", "-", "bit", "Python", "implementation", "of", "MurmurHash3", ";", "see", "http", ":", "//", "stackoverflow", ".", "com", "/", "questions", "/", "13305290", "/", "is", "-", "there", "-", "a", "-", "pure", "-", "python", "-", "implementation"...
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L452-L512
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
pymmh3_hash128_x64
def pymmh3_hash128_x64(key: Union[bytes, bytearray], seed: int) -> int: """ Implements 128-bit murmur3 hash for x64, as per ``pymmh3``, with some bugfixes. Args: key: data to hash seed: seed Returns: integer hash """ def fmix(k): k ^= k >> 33 k = (k...
python
def pymmh3_hash128_x64(key: Union[bytes, bytearray], seed: int) -> int: """ Implements 128-bit murmur3 hash for x64, as per ``pymmh3``, with some bugfixes. Args: key: data to hash seed: seed Returns: integer hash """ def fmix(k): k ^= k >> 33 k = (k...
[ "def", "pymmh3_hash128_x64", "(", "key", ":", "Union", "[", "bytes", ",", "bytearray", "]", ",", "seed", ":", "int", ")", "->", "int", ":", "def", "fmix", "(", "k", ")", ":", "k", "^=", "k", ">>", "33", "k", "=", "(", "k", "*", "0xff51afd7ed558cc...
Implements 128-bit murmur3 hash for x64, as per ``pymmh3``, with some bugfixes. Args: key: data to hash seed: seed Returns: integer hash
[ "Implements", "128", "-", "bit", "murmur3", "hash", "for", "x64", "as", "per", "pymmh3", "with", "some", "bugfixes", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L519-L655
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
pymmh3_hash128_x86
def pymmh3_hash128_x86(key: Union[bytes, bytearray], seed: int) -> int: """ Implements 128-bit murmur3 hash for x86, as per ``pymmh3``, with some bugfixes. Args: key: data to hash seed: seed Returns: integer hash """ def fmix(h): h ^= h >> 16 h = (h...
python
def pymmh3_hash128_x86(key: Union[bytes, bytearray], seed: int) -> int: """ Implements 128-bit murmur3 hash for x86, as per ``pymmh3``, with some bugfixes. Args: key: data to hash seed: seed Returns: integer hash """ def fmix(h): h ^= h >> 16 h = (h...
[ "def", "pymmh3_hash128_x86", "(", "key", ":", "Union", "[", "bytes", ",", "bytearray", "]", ",", "seed", ":", "int", ")", "->", "int", ":", "def", "fmix", "(", "h", ")", ":", "h", "^=", "h", ">>", "16", "h", "=", "(", "h", "*", "0x85ebca6b", ")...
Implements 128-bit murmur3 hash for x86, as per ``pymmh3``, with some bugfixes. Args: key: data to hash seed: seed Returns: integer hash
[ "Implements", "128", "-", "bit", "murmur3", "hash", "for", "x86", "as", "per", "pymmh3", "with", "some", "bugfixes", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L658-L846
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
pymmh3_hash128
def pymmh3_hash128(key: Union[bytes, bytearray], seed: int = 0, x64arch: bool = True) -> int: """ Implements 128bit murmur3 hash, as per ``pymmh3``. Args: key: data to hash seed: seed x64arch: is a 64-bit architecture available? Returns: ...
python
def pymmh3_hash128(key: Union[bytes, bytearray], seed: int = 0, x64arch: bool = True) -> int: """ Implements 128bit murmur3 hash, as per ``pymmh3``. Args: key: data to hash seed: seed x64arch: is a 64-bit architecture available? Returns: ...
[ "def", "pymmh3_hash128", "(", "key", ":", "Union", "[", "bytes", ",", "bytearray", "]", ",", "seed", ":", "int", "=", "0", ",", "x64arch", ":", "bool", "=", "True", ")", "->", "int", ":", "if", "x64arch", ":", "return", "pymmh3_hash128_x64", "(", "ke...
Implements 128bit murmur3 hash, as per ``pymmh3``. Args: key: data to hash seed: seed x64arch: is a 64-bit architecture available? Returns: integer hash
[ "Implements", "128bit", "murmur3", "hash", "as", "per", "pymmh3", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L849-L867
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
pymmh3_hash64
def pymmh3_hash64(key: Union[bytes, bytearray], seed: int = 0, x64arch: bool = True) -> Tuple[int, int]: """ Implements 64bit murmur3 hash, as per ``pymmh3``. Returns a tuple. Args: key: data to hash seed: seed x64arch: is a 64-bit architecture av...
python
def pymmh3_hash64(key: Union[bytes, bytearray], seed: int = 0, x64arch: bool = True) -> Tuple[int, int]: """ Implements 64bit murmur3 hash, as per ``pymmh3``. Returns a tuple. Args: key: data to hash seed: seed x64arch: is a 64-bit architecture av...
[ "def", "pymmh3_hash64", "(", "key", ":", "Union", "[", "bytes", ",", "bytearray", "]", ",", "seed", ":", "int", "=", "0", ",", "x64arch", ":", "bool", "=", "True", ")", "->", "Tuple", "[", "int", ",", "int", "]", ":", "hash_128", "=", "pymmh3_hash1...
Implements 64bit murmur3 hash, as per ``pymmh3``. Returns a tuple. Args: key: data to hash seed: seed x64arch: is a 64-bit architecture available? Returns: tuple: tuple of integers, ``(signed_val1, signed_val2)``
[ "Implements", "64bit", "murmur3", "hash", "as", "per", "pymmh3", ".", "Returns", "a", "tuple", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L870-L900
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
compare_python_to_reference_murmur3_32
def compare_python_to_reference_murmur3_32(data: Any, seed: int = 0) -> None: """ Checks the pure Python implementation of 32-bit murmur3 against the ``mmh3`` C-based module. Args: data: data to hash seed: seed Raises: AssertionError: if the two calculations don't match ...
python
def compare_python_to_reference_murmur3_32(data: Any, seed: int = 0) -> None: """ Checks the pure Python implementation of 32-bit murmur3 against the ``mmh3`` C-based module. Args: data: data to hash seed: seed Raises: AssertionError: if the two calculations don't match ...
[ "def", "compare_python_to_reference_murmur3_32", "(", "data", ":", "Any", ",", "seed", ":", "int", "=", "0", ")", "->", "None", ":", "assert", "mmh3", ",", "\"Need mmh3 module\"", "c_data", "=", "to_str", "(", "data", ")", "c_signed", "=", "mmh3", ".", "ha...
Checks the pure Python implementation of 32-bit murmur3 against the ``mmh3`` C-based module. Args: data: data to hash seed: seed Raises: AssertionError: if the two calculations don't match
[ "Checks", "the", "pure", "Python", "implementation", "of", "32", "-", "bit", "murmur3", "against", "the", "mmh3", "C", "-", "based", "module", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L907-L939
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
compare_python_to_reference_murmur3_64
def compare_python_to_reference_murmur3_64(data: Any, seed: int = 0) -> None: """ Checks the pure Python implementation of 64-bit murmur3 against the ``mmh3`` C-based module. Args: data: data to hash seed: seed Raises: AssertionError: if the two calculations don't match ...
python
def compare_python_to_reference_murmur3_64(data: Any, seed: int = 0) -> None: """ Checks the pure Python implementation of 64-bit murmur3 against the ``mmh3`` C-based module. Args: data: data to hash seed: seed Raises: AssertionError: if the two calculations don't match ...
[ "def", "compare_python_to_reference_murmur3_64", "(", "data", ":", "Any", ",", "seed", ":", "int", "=", "0", ")", "->", "None", ":", "assert", "mmh3", ",", "\"Need mmh3 module\"", "c_data", "=", "to_str", "(", "data", ")", "c_signed_low", ",", "c_signed_high",...
Checks the pure Python implementation of 64-bit murmur3 against the ``mmh3`` C-based module. Args: data: data to hash seed: seed Raises: AssertionError: if the two calculations don't match
[ "Checks", "the", "pure", "Python", "implementation", "of", "64", "-", "bit", "murmur3", "against", "the", "mmh3", "C", "-", "based", "module", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L942-L976
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
hash32
def hash32(data: Any, seed=0) -> int: """ Non-cryptographic, deterministic, fast hash. Args: data: data to hash seed: seed Returns: signed 32-bit integer """ with MultiTimerContext(timer, TIMING_HASH): c_data = to_str(data) if mmh3: return mm...
python
def hash32(data: Any, seed=0) -> int: """ Non-cryptographic, deterministic, fast hash. Args: data: data to hash seed: seed Returns: signed 32-bit integer """ with MultiTimerContext(timer, TIMING_HASH): c_data = to_str(data) if mmh3: return mm...
[ "def", "hash32", "(", "data", ":", "Any", ",", "seed", "=", "0", ")", "->", "int", ":", "with", "MultiTimerContext", "(", "timer", ",", "TIMING_HASH", ")", ":", "c_data", "=", "to_str", "(", "data", ")", "if", "mmh3", ":", "return", "mmh3", ".", "h...
Non-cryptographic, deterministic, fast hash. Args: data: data to hash seed: seed Returns: signed 32-bit integer
[ "Non", "-", "cryptographic", "deterministic", "fast", "hash", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L983-L1000
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
hash64
def hash64(data: Any, seed: int = 0) -> int: """ Non-cryptographic, deterministic, fast hash. Args: data: data to hash seed: seed Returns: signed 64-bit integer """ # ------------------------------------------------------------------------- # MurmurHash3 # -----...
python
def hash64(data: Any, seed: int = 0) -> int: """ Non-cryptographic, deterministic, fast hash. Args: data: data to hash seed: seed Returns: signed 64-bit integer """ # ------------------------------------------------------------------------- # MurmurHash3 # -----...
[ "def", "hash64", "(", "data", ":", "Any", ",", "seed", ":", "int", "=", "0", ")", "->", "int", ":", "# -------------------------------------------------------------------------", "# MurmurHash3", "# -------------------------------------------------------------------------", "c_...
Non-cryptographic, deterministic, fast hash. Args: data: data to hash seed: seed Returns: signed 64-bit integer
[ "Non", "-", "cryptographic", "deterministic", "fast", "hash", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L1003-L1023
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
main
def main() -> None: """ Command-line validation checks. """ _ = """ print(twos_comp_to_signed(0, n_bits=32)) # 0 print(twos_comp_to_signed(2 ** 31 - 1, n_bits=32)) # 2147483647 print(twos_comp_to_signed(2 ** 31, n_bits=32)) # -2147483648 == -(2 ** 31) print(twos_comp_to_signed(2 ** 32...
python
def main() -> None: """ Command-line validation checks. """ _ = """ print(twos_comp_to_signed(0, n_bits=32)) # 0 print(twos_comp_to_signed(2 ** 31 - 1, n_bits=32)) # 2147483647 print(twos_comp_to_signed(2 ** 31, n_bits=32)) # -2147483648 == -(2 ** 31) print(twos_comp_to_signed(2 ** 32...
[ "def", "main", "(", ")", "->", "None", ":", "_", "=", "\"\"\"\n print(twos_comp_to_signed(0, n_bits=32)) # 0\n print(twos_comp_to_signed(2 ** 31 - 1, n_bits=32)) # 2147483647\n print(twos_comp_to_signed(2 ** 31, n_bits=32)) # -2147483648 == -(2 ** 31)\n print(twos_comp_to_signed(2 *...
Command-line validation checks.
[ "Command", "-", "line", "validation", "checks", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L1042-L1062
RudolfCardinal/pythonlib
cardinal_pythonlib/hash.py
GenericHmacHasher.hash
def hash(self, raw: Any) -> str: """ Returns the hex digest of a HMAC-encoded version of the input. """ with MultiTimerContext(timer, TIMING_HASH): raw_bytes = str(raw).encode('utf-8') hmac_obj = hmac.new(key=self.key_bytes, msg=raw_bytes, ...
python
def hash(self, raw: Any) -> str: """ Returns the hex digest of a HMAC-encoded version of the input. """ with MultiTimerContext(timer, TIMING_HASH): raw_bytes = str(raw).encode('utf-8') hmac_obj = hmac.new(key=self.key_bytes, msg=raw_bytes, ...
[ "def", "hash", "(", "self", ",", "raw", ":", "Any", ")", "->", "str", ":", "with", "MultiTimerContext", "(", "timer", ",", "TIMING_HASH", ")", ":", "raw_bytes", "=", "str", "(", "raw", ")", ".", "encode", "(", "'utf-8'", ")", "hmac_obj", "=", "hmac",...
Returns the hex digest of a HMAC-encoded version of the input.
[ "Returns", "the", "hex", "digest", "of", "a", "HMAC", "-", "encoded", "version", "of", "the", "input", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/hash.py#L188-L196
RudolfCardinal/pythonlib
cardinal_pythonlib/maths_py.py
mean
def mean(values: Sequence[Union[int, float, None]]) -> Optional[float]: """ Returns the mean of a list of numbers. Args: values: values to mean, ignoring any values that are ``None`` Returns: the mean, or ``None`` if :math:`n = 0` """ total = 0.0 # starting with "0.0" causes ...
python
def mean(values: Sequence[Union[int, float, None]]) -> Optional[float]: """ Returns the mean of a list of numbers. Args: values: values to mean, ignoring any values that are ``None`` Returns: the mean, or ``None`` if :math:`n = 0` """ total = 0.0 # starting with "0.0" causes ...
[ "def", "mean", "(", "values", ":", "Sequence", "[", "Union", "[", "int", ",", "float", ",", "None", "]", "]", ")", "->", "Optional", "[", "float", "]", ":", "total", "=", "0.0", "# starting with \"0.0\" causes automatic conversion to float", "n", "=", "0", ...
Returns the mean of a list of numbers. Args: values: values to mean, ignoring any values that are ``None`` Returns: the mean, or ``None`` if :math:`n = 0`
[ "Returns", "the", "mean", "of", "a", "list", "of", "numbers", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/maths_py.py#L41-L58
RudolfCardinal/pythonlib
cardinal_pythonlib/maths_py.py
safe_logit
def safe_logit(p: Union[float, int]) -> Optional[float]: r""" Returns the logit (log odds) of its input probability .. math:: \alpha = logit(p) = log(x / (1 - x)) Args: p: :math:`p` Returns: :math:`\alpha`, or ``None`` if ``x`` is not in the range [0, 1]. """ if ...
python
def safe_logit(p: Union[float, int]) -> Optional[float]: r""" Returns the logit (log odds) of its input probability .. math:: \alpha = logit(p) = log(x / (1 - x)) Args: p: :math:`p` Returns: :math:`\alpha`, or ``None`` if ``x`` is not in the range [0, 1]. """ if ...
[ "def", "safe_logit", "(", "p", ":", "Union", "[", "float", ",", "int", "]", ")", "->", "Optional", "[", "float", "]", ":", "if", "p", ">", "1", "or", "p", "<", "0", ":", "return", "None", "# can't take log of negative number", "if", "p", "==", "1", ...
r""" Returns the logit (log odds) of its input probability .. math:: \alpha = logit(p) = log(x / (1 - x)) Args: p: :math:`p` Returns: :math:`\alpha`, or ``None`` if ``x`` is not in the range [0, 1].
[ "r", "Returns", "the", "logit", "(", "log", "odds", ")", "of", "its", "input", "probability" ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/maths_py.py#L65-L86
RudolfCardinal/pythonlib
cardinal_pythonlib/maths_py.py
normal_round_float
def normal_round_float(x: float, dp: int = 0) -> float: """ Hmpf. Shouldn't need to have to implement this, but... Conventional rounding to integer via the "round half away from zero" method, e.g. .. code-block:: none 1.1 -> 1 1.5 -> 2 1.6 -> 2 2.0 -> 2 -1...
python
def normal_round_float(x: float, dp: int = 0) -> float: """ Hmpf. Shouldn't need to have to implement this, but... Conventional rounding to integer via the "round half away from zero" method, e.g. .. code-block:: none 1.1 -> 1 1.5 -> 2 1.6 -> 2 2.0 -> 2 -1...
[ "def", "normal_round_float", "(", "x", ":", "float", ",", "dp", ":", "int", "=", "0", ")", "->", "float", ":", "if", "not", "math", ".", "isfinite", "(", "x", ")", ":", "return", "x", "factor", "=", "pow", "(", "10", ",", "dp", ")", "x", "=", ...
Hmpf. Shouldn't need to have to implement this, but... Conventional rounding to integer via the "round half away from zero" method, e.g. .. code-block:: none 1.1 -> 1 1.5 -> 2 1.6 -> 2 2.0 -> 2 -1.6 -> -2 etc. ... or the equivalent for a certain numbe...
[ "Hmpf", ".", "Shouldn", "t", "need", "to", "have", "to", "implement", "this", "but", "..." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/maths_py.py#L93-L125
RudolfCardinal/pythonlib
cardinal_pythonlib/maths_py.py
normal_round_int
def normal_round_int(x: float) -> int: """ Version of :func:`normal_round_float` but guaranteed to return an `int`. """ if not math.isfinite(x): raise ValueError("Input to normal_round_int() is not finite") if x >= 0: # noinspection PyTypeChecker return math.floor(x + 0.5) ...
python
def normal_round_int(x: float) -> int: """ Version of :func:`normal_round_float` but guaranteed to return an `int`. """ if not math.isfinite(x): raise ValueError("Input to normal_round_int() is not finite") if x >= 0: # noinspection PyTypeChecker return math.floor(x + 0.5) ...
[ "def", "normal_round_int", "(", "x", ":", "float", ")", "->", "int", ":", "if", "not", "math", ".", "isfinite", "(", "x", ")", ":", "raise", "ValueError", "(", "\"Input to normal_round_int() is not finite\"", ")", "if", "x", ">=", "0", ":", "# noinspection P...
Version of :func:`normal_round_float` but guaranteed to return an `int`.
[ "Version", "of", ":", "func", ":", "normal_round_float", "but", "guaranteed", "to", "return", "an", "int", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/maths_py.py#L128-L139
RudolfCardinal/pythonlib
cardinal_pythonlib/tools/backup_mysql_database.py
cmdargs
def cmdargs(mysqldump: str, username: str, password: str, database: str, verbose: bool, with_drop_create_database: bool, max_allowed_packet: str, hide_password: bool = False) -> List[str]: """ Returns command arguments for a ``m...
python
def cmdargs(mysqldump: str, username: str, password: str, database: str, verbose: bool, with_drop_create_database: bool, max_allowed_packet: str, hide_password: bool = False) -> List[str]: """ Returns command arguments for a ``m...
[ "def", "cmdargs", "(", "mysqldump", ":", "str", ",", "username", ":", "str", ",", "password", ":", "str", ",", "database", ":", "str", ",", "verbose", ":", "bool", ",", "with_drop_create_database", ":", "bool", ",", "max_allowed_packet", ":", "str", ",", ...
Returns command arguments for a ``mysqldump`` call. Args: mysqldump: ``mysqldump`` executable filename username: user name password: password database: database name verbose: verbose output? with_drop_create_database: produce commands to ``DROP`` the database ...
[ "Returns", "command", "arguments", "for", "a", "mysqldump", "call", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/tools/backup_mysql_database.py#L46-L90
RudolfCardinal/pythonlib
cardinal_pythonlib/tools/backup_mysql_database.py
main
def main() -> None: """ Command-line processor. See ``--help`` for details. """ main_only_quicksetup_rootlogger() wdcd_suffix = "_with_drop_create_database" timeformat = "%Y%m%dT%H%M%S" parser = argparse.ArgumentParser( description=""" Back up a specific MySQL database. The r...
python
def main() -> None: """ Command-line processor. See ``--help`` for details. """ main_only_quicksetup_rootlogger() wdcd_suffix = "_with_drop_create_database" timeformat = "%Y%m%dT%H%M%S" parser = argparse.ArgumentParser( description=""" Back up a specific MySQL database. The r...
[ "def", "main", "(", ")", "->", "None", ":", "main_only_quicksetup_rootlogger", "(", ")", "wdcd_suffix", "=", "\"_with_drop_create_database\"", "timeformat", "=", "\"%Y%m%dT%H%M%S\"", "parser", "=", "argparse", ".", "ArgumentParser", "(", "description", "=", "\"\"\"\n ...
Command-line processor. See ``--help`` for details.
[ "Command", "-", "line", "processor", ".", "See", "--", "help", "for", "details", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/tools/backup_mysql_database.py#L93-L190
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/dialect.py
get_dialect
def get_dialect(mixed: Union[SQLCompiler, Engine, Dialect]) -> Dialect: """ Finds the SQLAlchemy dialect in use. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Dialect` object Returns: the SQLAlchemy :class:`Dialect` being used """ if isinstan...
python
def get_dialect(mixed: Union[SQLCompiler, Engine, Dialect]) -> Dialect: """ Finds the SQLAlchemy dialect in use. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Dialect` object Returns: the SQLAlchemy :class:`Dialect` being used """ if isinstan...
[ "def", "get_dialect", "(", "mixed", ":", "Union", "[", "SQLCompiler", ",", "Engine", ",", "Dialect", "]", ")", "->", "Dialect", ":", "if", "isinstance", "(", "mixed", ",", "Dialect", ")", ":", "return", "mixed", "elif", "isinstance", "(", "mixed", ",", ...
Finds the SQLAlchemy dialect in use. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Dialect` object Returns: the SQLAlchemy :class:`Dialect` being used
[ "Finds", "the", "SQLAlchemy", "dialect", "in", "use", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/dialect.py#L65-L83
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/dialect.py
get_dialect_name
def get_dialect_name(mixed: Union[SQLCompiler, Engine, Dialect]) -> str: """ Finds the name of the SQLAlchemy dialect in use. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Dialect` object Returns: the SQLAlchemy dialect name being used """ dia...
python
def get_dialect_name(mixed: Union[SQLCompiler, Engine, Dialect]) -> str: """ Finds the name of the SQLAlchemy dialect in use. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Dialect` object Returns: the SQLAlchemy dialect name being used """ dia...
[ "def", "get_dialect_name", "(", "mixed", ":", "Union", "[", "SQLCompiler", ",", "Engine", ",", "Dialect", "]", ")", "->", "str", ":", "dialect", "=", "get_dialect", "(", "mixed", ")", "# noinspection PyUnresolvedReferences", "return", "dialect", ".", "name" ]
Finds the name of the SQLAlchemy dialect in use. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Dialect` object Returns: the SQLAlchemy dialect name being used
[ "Finds", "the", "name", "of", "the", "SQLAlchemy", "dialect", "in", "use", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/dialect.py#L86-L98
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/dialect.py
get_preparer
def get_preparer(mixed: Union[SQLCompiler, Engine, Dialect]) -> IdentifierPreparer: """ Returns the SQLAlchemy :class:`IdentifierPreparer` in use for the dialect being used. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Di...
python
def get_preparer(mixed: Union[SQLCompiler, Engine, Dialect]) -> IdentifierPreparer: """ Returns the SQLAlchemy :class:`IdentifierPreparer` in use for the dialect being used. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Di...
[ "def", "get_preparer", "(", "mixed", ":", "Union", "[", "SQLCompiler", ",", "Engine", ",", "Dialect", "]", ")", "->", "IdentifierPreparer", ":", "dialect", "=", "get_dialect", "(", "mixed", ")", "# noinspection PyUnresolvedReferences", "return", "dialect", ".", ...
Returns the SQLAlchemy :class:`IdentifierPreparer` in use for the dialect being used. Args: mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Dialect` object Returns: an :class:`IdentifierPreparer`
[ "Returns", "the", "SQLAlchemy", ":", "class", ":", "IdentifierPreparer", "in", "use", "for", "the", "dialect", "being", "used", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/dialect.py#L101-L116
RudolfCardinal/pythonlib
cardinal_pythonlib/sqlalchemy/dialect.py
quote_identifier
def quote_identifier(identifier: str, mixed: Union[SQLCompiler, Engine, Dialect]) -> str: """ Converts an SQL identifier to a quoted version, via the SQL dialect in use. Args: identifier: the identifier to be quoted mixed: an SQLAlchemy :class:`SQLCompiler`, :class:...
python
def quote_identifier(identifier: str, mixed: Union[SQLCompiler, Engine, Dialect]) -> str: """ Converts an SQL identifier to a quoted version, via the SQL dialect in use. Args: identifier: the identifier to be quoted mixed: an SQLAlchemy :class:`SQLCompiler`, :class:...
[ "def", "quote_identifier", "(", "identifier", ":", "str", ",", "mixed", ":", "Union", "[", "SQLCompiler", ",", "Engine", ",", "Dialect", "]", ")", "->", "str", ":", "# See also http://sqlalchemy-utils.readthedocs.io/en/latest/_modules/sqlalchemy_utils/functions/orm.html # ...
Converts an SQL identifier to a quoted version, via the SQL dialect in use. Args: identifier: the identifier to be quoted mixed: an SQLAlchemy :class:`SQLCompiler`, :class:`Engine`, or :class:`Dialect` object Returns: the quoted identifier
[ "Converts", "an", "SQL", "identifier", "to", "a", "quoted", "version", "via", "the", "SQL", "dialect", "in", "use", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/sqlalchemy/dialect.py#L119-L135
renatahodovan/antlerinator
antlerinator/install.py
install
def install(force=False, lazy=False): """ Download the ANTLR v4 tool jar. (Raises :exception:`OSError` if jar is already available, unless ``lazy`` is ``True``.) :param bool force: Force download even if local jar already exists. :param bool lazy: Don't report an error if local jar already exists a...
python
def install(force=False, lazy=False): """ Download the ANTLR v4 tool jar. (Raises :exception:`OSError` if jar is already available, unless ``lazy`` is ``True``.) :param bool force: Force download even if local jar already exists. :param bool lazy: Don't report an error if local jar already exists a...
[ "def", "install", "(", "force", "=", "False", ",", "lazy", "=", "False", ")", ":", "if", "exists", "(", "antlr_jar_path", ")", ":", "if", "lazy", ":", "return", "if", "not", "force", ":", "raise", "OSError", "(", "errno", ".", "EEXIST", ",", "'file a...
Download the ANTLR v4 tool jar. (Raises :exception:`OSError` if jar is already available, unless ``lazy`` is ``True``.) :param bool force: Force download even if local jar already exists. :param bool lazy: Don't report an error if local jar already exists and don't try to download it either.
[ "Download", "the", "ANTLR", "v4", "tool", "jar", ".", "(", "Raises", ":", "exception", ":", "OSError", "if", "jar", "is", "already", "available", "unless", "lazy", "is", "True", ".", ")" ]
train
https://github.com/renatahodovan/antlerinator/blob/02b165d758014bc064991e5dbc05f4b39f2bb5c9/antlerinator/install.py#L29-L54
renatahodovan/antlerinator
antlerinator/install.py
execute
def execute(): """ Entry point of the install helper tool to ease the download of the right version of the ANTLR v4 tool jar. """ arg_parser = ArgumentParser(description='Install helper tool to download the right version of the ANTLR v4 tool jar.') arg_parser.add_argument('--version', action='...
python
def execute(): """ Entry point of the install helper tool to ease the download of the right version of the ANTLR v4 tool jar. """ arg_parser = ArgumentParser(description='Install helper tool to download the right version of the ANTLR v4 tool jar.') arg_parser.add_argument('--version', action='...
[ "def", "execute", "(", ")", ":", "arg_parser", "=", "ArgumentParser", "(", "description", "=", "'Install helper tool to download the right version of the ANTLR v4 tool jar.'", ")", "arg_parser", ".", "add_argument", "(", "'--version'", ",", "action", "=", "'version'", ","...
Entry point of the install helper tool to ease the download of the right version of the ANTLR v4 tool jar.
[ "Entry", "point", "of", "the", "install", "helper", "tool", "to", "ease", "the", "download", "of", "the", "right", "version", "of", "the", "ANTLR", "v4", "tool", "jar", "." ]
train
https://github.com/renatahodovan/antlerinator/blob/02b165d758014bc064991e5dbc05f4b39f2bb5c9/antlerinator/install.py#L57-L75
RudolfCardinal/pythonlib
cardinal_pythonlib/tsv.py
tsv_escape
def tsv_escape(x: Any) -> str: """ Escape data for tab-separated value (TSV) format. """ if x is None: return "" x = str(x) return x.replace("\t", "\\t").replace("\n", "\\n")
python
def tsv_escape(x: Any) -> str: """ Escape data for tab-separated value (TSV) format. """ if x is None: return "" x = str(x) return x.replace("\t", "\\t").replace("\n", "\\n")
[ "def", "tsv_escape", "(", "x", ":", "Any", ")", "->", "str", ":", "if", "x", "is", "None", ":", "return", "\"\"", "x", "=", "str", "(", "x", ")", "return", "x", ".", "replace", "(", "\"\\t\"", ",", "\"\\\\t\"", ")", ".", "replace", "(", "\"\\n\""...
Escape data for tab-separated value (TSV) format.
[ "Escape", "data", "for", "tab", "-", "separated", "value", "(", "TSV", ")", "format", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/tsv.py#L38-L45
RudolfCardinal/pythonlib
cardinal_pythonlib/tsv.py
make_tsv_row
def make_tsv_row(values: List[Any]) -> str: """ From a list of values, make a TSV line. """ return "\t".join([tsv_escape(x) for x in values]) + "\n"
python
def make_tsv_row(values: List[Any]) -> str: """ From a list of values, make a TSV line. """ return "\t".join([tsv_escape(x) for x in values]) + "\n"
[ "def", "make_tsv_row", "(", "values", ":", "List", "[", "Any", "]", ")", "->", "str", ":", "return", "\"\\t\"", ".", "join", "(", "[", "tsv_escape", "(", "x", ")", "for", "x", "in", "values", "]", ")", "+", "\"\\n\"" ]
From a list of values, make a TSV line.
[ "From", "a", "list", "of", "values", "make", "a", "TSV", "line", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/tsv.py#L48-L52
RudolfCardinal/pythonlib
cardinal_pythonlib/tsv.py
dictlist_to_tsv
def dictlist_to_tsv(dictlist: List[Dict[str, Any]]) -> str: """ From a consistent list of dictionaries mapping fieldnames to values, make a TSV file. """ if not dictlist: return "" fieldnames = dictlist[0].keys() tsv = "\t".join([tsv_escape(f) for f in fieldnames]) + "\n" for d i...
python
def dictlist_to_tsv(dictlist: List[Dict[str, Any]]) -> str: """ From a consistent list of dictionaries mapping fieldnames to values, make a TSV file. """ if not dictlist: return "" fieldnames = dictlist[0].keys() tsv = "\t".join([tsv_escape(f) for f in fieldnames]) + "\n" for d i...
[ "def", "dictlist_to_tsv", "(", "dictlist", ":", "List", "[", "Dict", "[", "str", ",", "Any", "]", "]", ")", "->", "str", ":", "if", "not", "dictlist", ":", "return", "\"\"", "fieldnames", "=", "dictlist", "[", "0", "]", ".", "keys", "(", ")", "tsv"...
From a consistent list of dictionaries mapping fieldnames to values, make a TSV file.
[ "From", "a", "consistent", "list", "of", "dictionaries", "mapping", "fieldnames", "to", "values", "make", "a", "TSV", "file", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/tsv.py#L55-L66
RudolfCardinal/pythonlib
cardinal_pythonlib/tsv.py
tsv_pairs_to_dict
def tsv_pairs_to_dict(line: str, key_lower: bool = True) -> Dict[str, str]: r""" Converts a TSV line into sequential key/value pairs as a dictionary. For example, .. code-block:: none field1\tvalue1\tfield2\tvalue2 becomes .. code-block:: none {"field1": "value1", "field2":...
python
def tsv_pairs_to_dict(line: str, key_lower: bool = True) -> Dict[str, str]: r""" Converts a TSV line into sequential key/value pairs as a dictionary. For example, .. code-block:: none field1\tvalue1\tfield2\tvalue2 becomes .. code-block:: none {"field1": "value1", "field2":...
[ "def", "tsv_pairs_to_dict", "(", "line", ":", "str", ",", "key_lower", ":", "bool", "=", "True", ")", "->", "Dict", "[", "str", ",", "str", "]", ":", "items", "=", "line", ".", "split", "(", "\"\\t\"", ")", "d", "=", "{", "}", "# type: Dict[str, str]...
r""" Converts a TSV line into sequential key/value pairs as a dictionary. For example, .. code-block:: none field1\tvalue1\tfield2\tvalue2 becomes .. code-block:: none {"field1": "value1", "field2": "value2"} Args: line: the line key_lower: should the keys ...
[ "r", "Converts", "a", "TSV", "line", "into", "sequential", "key", "/", "value", "pairs", "as", "a", "dictionary", "." ]
train
https://github.com/RudolfCardinal/pythonlib/blob/0b84cb35f38bd7d8723958dae51b480a829b7227/cardinal_pythonlib/tsv.py#L69-L101