actio_python_utils.database_functions.replace_dict_values_with_global_definition¶
- actio_python_utils.database_functions.replace_dict_values_with_global_definition(mapping, global_mapping={'Any': typing.Any, 'Callable': <class 'collections.abc.Callable'>, 'CustomCSVDialect': <class 'actio_python_utils.utils.CustomCSVDialect'>, 'DBConnection': <class 'actio_python_utils.database_functions.DBConnection'>, 'DictCursor': <class 'psycopg2.extras.DictCursor'>, 'Hashable': <class 'collections.abc.Hashable'>, 'Iterable': <class 'collections.abc.Iterable'>, 'LoggingCursor': <class 'actio_python_utils.database_functions.LoggingCursor'>, 'Mapping': <class 'collections.abc.Mapping'>, 'MutableMapping': <class 'collections.abc.MutableMapping'>, 'Optional': typing.Optional, 'SavepointCursor': <class 'actio_python_utils.database_functions.SavepointCursor'>, 'TracebackType': <class 'traceback'>, '__annotations__': {}, '__builtins__': {'ArithmeticError': <class 'ArithmeticError'>, 'AssertionError': <class 'AssertionError'>, 'AttributeError': <class 'AttributeError'>, 'BaseException': <class 'BaseException'>, 'BlockingIOError': <class 'BlockingIOError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'BufferError': <class 'BufferError'>, 'BytesWarning': <class 'BytesWarning'>, 'ChildProcessError': <class 'ChildProcessError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, 'ConnectionError': <class 'ConnectionError'>, 'ConnectionRefusedError': <class 'ConnectionRefusedError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'DeprecationWarning': <class 'DeprecationWarning'>, 'EOFError': <class 'EOFError'>, 'Ellipsis': Ellipsis, 'EncodingWarning': <class 'EncodingWarning'>, 'EnvironmentError': <class 'OSError'>, 'Exception': <class 'Exception'>, 'False': False, 'FileExistsError': <class 'FileExistsError'>, 'FileNotFoundError': <class 'FileNotFoundError'>, 'FloatingPointError': <class 'FloatingPointError'>, 'FutureWarning': <class 'FutureWarning'>, 'GeneratorExit': <class 'GeneratorExit'>, 'IOError': <class 'OSError'>, 'ImportError': <class 'ImportError'>, 'ImportWarning': <class 'ImportWarning'>, 'IndentationError': <class 'IndentationError'>, 'IndexError': <class 'IndexError'>, 'InterruptedError': <class 'InterruptedError'>, 'IsADirectoryError': <class 'IsADirectoryError'>, 'KeyError': <class 'KeyError'>, 'KeyboardInterrupt': <class 'KeyboardInterrupt'>, 'LookupError': <class 'LookupError'>, 'MemoryError': <class 'MemoryError'>, 'ModuleNotFoundError': <class 'ModuleNotFoundError'>, 'NameError': <class 'NameError'>, 'None': None, 'NotADirectoryError': <class 'NotADirectoryError'>, 'NotImplemented': NotImplemented, 'NotImplementedError': <class 'NotImplementedError'>, 'OSError': <class 'OSError'>, 'OverflowError': <class 'OverflowError'>, 'PendingDeprecationWarning': <class 'PendingDeprecationWarning'>, 'PermissionError': <class 'PermissionError'>, 'ProcessLookupError': <class 'ProcessLookupError'>, 'RecursionError': <class 'RecursionError'>, 'ReferenceError': <class 'ReferenceError'>, 'ResourceWarning': <class 'ResourceWarning'>, 'RuntimeError': <class 'RuntimeError'>, 'RuntimeWarning': <class 'RuntimeWarning'>, 'StopAsyncIteration': <class 'StopAsyncIteration'>, 'StopIteration': <class 'StopIteration'>, 'SyntaxError': <class 'SyntaxError'>, 'SyntaxWarning': <class 'SyntaxWarning'>, 'SystemError': <class 'SystemError'>, 'SystemExit': <class 'SystemExit'>, 'TabError': <class 'TabError'>, 'TimeoutError': <class 'TimeoutError'>, 'True': True, 'TypeError': <class 'TypeError'>, 'UnboundLocalError': <class 'UnboundLocalError'>, 'UnicodeDecodeError': <class 'UnicodeDecodeError'>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>, 'UnicodeError': <class 'UnicodeError'>, 'UnicodeTranslateError': <class 'UnicodeTranslateError'>, 'UnicodeWarning': <class 'UnicodeWarning'>, 'UserWarning': <class 'UserWarning'>, 'ValueError': <class 'ValueError'>, 'Warning': <class 'Warning'>, 'ZeroDivisionError': <class 'ZeroDivisionError'>, '__build_class__': <built-in function __build_class__>, '__debug__': True, '__doc__': "Built-in functions, exceptions, and other objects.\\n\\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", '__import__': <built-in function __import__>, '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__name__': 'builtins', '__package__': '', '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>, origin='built-in'), 'abs': <built-in function abs>, 'aiter': <built-in function aiter>, 'all': <built-in function all>, 'anext': <built-in function anext>, 'any': <built-in function any>, 'ascii': <built-in function ascii>, 'bin': <built-in function bin>, 'bool': <class 'bool'>, 'breakpoint': <built-in function breakpoint>, 'bytearray': <class 'bytearray'>, 'bytes': <class 'bytes'>, 'callable': <built-in function callable>, 'chr': <built-in function chr>, 'classmethod': <class 'classmethod'>, 'compile': <built-in function compile>, 'complex': <class 'complex'>, 'copyright': Copyright (c) 2001-2023 Python Software Foundation. All Rights Reserved. Copyright (c) 2000 BeOpen.com. All Rights Reserved. Copyright (c) 1995-2001 Corporation for National Research Initiatives. All Rights Reserved. Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. All Rights Reserved., 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands for supporting Python development. See www.python.org for more information., 'delattr': <built-in function delattr>, 'dict': <class 'dict'>, 'dir': <built-in function dir>, 'divmod': <built-in function divmod>, 'enumerate': <class 'enumerate'>, 'eval': <built-in function eval>, 'exec': <built-in function exec>, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'filter': <class 'filter'>, 'float': <class 'float'>, 'format': <built-in function format>, 'frozenset': <class 'frozenset'>, 'getattr': <built-in function getattr>, 'globals': <built-in function globals>, 'hasattr': <built-in function hasattr>, 'hash': <built-in function hash>, 'help': Type help() for interactive help, or help(object) for help about object., 'hex': <built-in function hex>, 'id': <built-in function id>, 'input': <built-in function input>, 'int': <class 'int'>, 'isinstance': <built-in function isinstance>, 'issubclass': <built-in function issubclass>, 'iter': <built-in function iter>, 'len': <built-in function len>, 'license': Type license() to see the full license text, 'list': <class 'list'>, 'locals': <built-in function locals>, 'map': <class 'map'>, 'max': <built-in function max>, 'memoryview': <class 'memoryview'>, 'min': <built-in function min>, 'next': <built-in function next>, 'object': <class 'object'>, 'oct': <built-in function oct>, 'open': <built-in function open>, 'ord': <built-in function ord>, 'pow': <built-in function pow>, 'print': <built-in function print>, 'property': <class 'property'>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'range': <class 'range'>, 'repr': <built-in function repr>, 'reversed': <class 'reversed'>, 'round': <built-in function round>, 'set': <class 'set'>, 'setattr': <built-in function setattr>, 'slice': <class 'slice'>, 'sorted': <built-in function sorted>, 'staticmethod': <class 'staticmethod'>, 'str': <class 'str'>, 'sum': <built-in function sum>, 'super': <class 'super'>, 'tuple': <class 'tuple'>, 'type': <class 'type'>, 'vars': <built-in function vars>, 'zip': <class 'zip'>}, '__cached__': '/Users/nick/github/actio_python_utils/actio_python_utils/__pycache__/database_functions.cpython-310.pyc', '__doc__': '\\nDatabase-related functionality.\\n', '__file__': '/Users/nick/github/actio_python_utils/actio_python_utils/database_functions.py', '__loader__': <_frozen_importlib_external.SourceFileLoader object>, '__name__': 'actio_python_utils.database_functions', '__package__': 'actio_python_utils', '__spec__': ModuleSpec(name='actio_python_utils.database_functions', loader=<_frozen_importlib_external.SourceFileLoader object>, origin='/Users/nick/github/actio_python_utils/actio_python_utils/database_functions.py'), 'cfg': {'data': {'directory': 'data'}, 'db': {'cursor_factory': <class 'actio_python_utils.database_functions.LoggingCursor'>, 'service': 'bioinfo_data_psql'}, 'loading': {'escape': '\\'"\\'', 'quote': '\\'"\\'', 'sanitize': False}, 'logging': {'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s', 'level': 'INFO', 'loggers_to_ignore': ['parso.cache', 'parso.python.diff'], 'names': {'db': 'sql_debug'}}, 'output': 'output', 'spark': {'codecs': {'glow': 'io.projectglow.sql.util.BGZFCodec'}, 'cores': '*', 'jdbc': '/usr/share/java/postgresql-42.6.0.jar', 'memory': '1g', 'packages': {'excel': 'com.crealytics:spark-excel_2.12:3.3.1_0.18.7', 'glow': 'io.projectglow:glow-spark3_2.12:1.2.1', 'xml': 'com.databricks:spark-xml_2.12:0.15.0'}}}, 'connect_to_db': <function connect_to_db>, 'contextmanager': <function contextmanager>, 'get_csv_fields': <function get_csv_fields>, 'get_db_args': <function get_db_args>, 'get_pg_config': <function get_pg_config>, 'logger': <Logger actio_python_utils.database_functions (WARNING)>, 'logging': <module 'logging' from '/Users/nick/miniconda3/lib/python3.10/logging/__init__.py'>, 'nullcontext': <class 'contextlib.nullcontext'>, 'os': <module 'os' from '/Users/nick/miniconda3/lib/python3.10/os.py'>, 'pgtoolkit': <module 'pgtoolkit' from '/Users/nick/miniconda3/lib/python3.10/site-packages/pgtoolkit/__init__.py'>, 'psycopg2': <module 'psycopg2' from '/Users/nick/miniconda3/lib/python3.10/site-packages/psycopg2/__init__.py'>, 'rename_dict_keys': <function rename_dict_keys>, 'replace_dict_values_with_global_definition': <function replace_dict_values_with_global_definition>, 'savepoint': <function savepoint>, 'savepoint_wrapper': <function savepoint_wrapper>, 'split_schema_from_table': <function split_schema_from_table>, 'wraps': <function wraps>, 'zopen': <function zopen>})[source]¶
Replaces values in the mapping with those in global_mapping when the value is a str and it is a key in the global mapping
- Parameters:
mapping (
MutableMapping
[Hashable
,Any
]) – The mapping for which to replace valuesglobal_mapping (
Mapping
[Hashable
,Any
], default:{'__name__': 'actio_python_utils.database_functions', '__doc__': '\\nDatabase-related functionality.\\n', '__package__': 'actio_python_utils', '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7fa8d8d8bcd0>, '__spec__': ModuleSpec(name='actio_python_utils.database_functions', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fa8d8d8bcd0>, origin='/Users/nick/github/actio_python_utils/actio_python_utils/database_functions.py'), '__file__': '/Users/nick/github/actio_python_utils/actio_python_utils/database_functions.py', '__cached__': '/Users/nick/github/actio_python_utils/actio_python_utils/__pycache__/database_functions.cpython-310.pyc', '__builtins__': {'__name__': 'builtins', '__doc__': "Built-in functions, exceptions, and other objects.\\n\\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", '__package__': '', '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>, origin='built-in'), '__build_class__': <built-in function __build_class__>, '__import__': <built-in function __import__>, 'abs': <built-in function abs>, 'all': <built-in function all>, 'any': <built-in function any>, 'ascii': <built-in function ascii>, 'bin': <built-in function bin>, 'breakpoint': <built-in function breakpoint>, 'callable': <built-in function callable>, 'chr': <built-in function chr>, 'compile': <built-in function compile>, 'delattr': <built-in function delattr>, 'dir': <built-in function dir>, 'divmod': <built-in function divmod>, 'eval': <built-in function eval>, 'exec': <built-in function exec>, 'format': <built-in function format>, 'getattr': <built-in function getattr>, 'globals': <built-in function globals>, 'hasattr': <built-in function hasattr>, 'hash': <built-in function hash>, 'hex': <built-in function hex>, 'id': <built-in function id>, 'input': <built-in function input>, 'isinstance': <built-in function isinstance>, 'issubclass': <built-in function issubclass>, 'iter': <built-in function iter>, 'aiter': <built-in function aiter>, 'len': <built-in function len>, 'locals': <built-in function locals>, 'max': <built-in function max>, 'min': <built-in function min>, 'next': <built-in function next>, 'anext': <built-in function anext>, 'oct': <built-in function oct>, 'ord': <built-in function ord>, 'pow': <built-in function pow>, 'print': <built-in function print>, 'repr': <built-in function repr>, 'round': <built-in function round>, 'setattr': <built-in function setattr>, 'sorted': <built-in function sorted>, 'sum': <built-in function sum>, 'vars': <built-in function vars>, 'None': None, 'Ellipsis': Ellipsis, 'NotImplemented': NotImplemented, 'False': False, 'True': True, 'bool': <class 'bool'>, 'memoryview': <class 'memoryview'>, 'bytearray': <class 'bytearray'>, 'bytes': <class 'bytes'>, 'classmethod': <class 'classmethod'>, 'complex': <class 'complex'>, 'dict': <class 'dict'>, 'enumerate': <class 'enumerate'>, 'filter': <class 'filter'>, 'float': <class 'float'>, 'frozenset': <class 'frozenset'>, 'property': <class 'property'>, 'int': <class 'int'>, 'list': <class 'list'>, 'map': <class 'map'>, 'object': <class 'object'>, 'range': <class 'range'>, 'reversed': <class 'reversed'>, 'set': <class 'set'>, 'slice': <class 'slice'>, 'staticmethod': <class 'staticmethod'>, 'str': <class 'str'>, 'super': <class 'super'>, 'tuple': <class 'tuple'>, 'type': <class 'type'>, 'zip': <class 'zip'>, '__debug__': True, 'BaseException': <class 'BaseException'>, 'Exception': <class 'Exception'>, 'TypeError': <class 'TypeError'>, 'StopAsyncIteration': <class 'StopAsyncIteration'>, 'StopIteration': <class 'StopIteration'>, 'GeneratorExit': <class 'GeneratorExit'>, 'SystemExit': <class 'SystemExit'>, 'KeyboardInterrupt': <class 'KeyboardInterrupt'>, 'ImportError': <class 'ImportError'>, 'ModuleNotFoundError': <class 'ModuleNotFoundError'>, 'OSError': <class 'OSError'>, 'EnvironmentError': <class 'OSError'>, 'IOError': <class 'OSError'>, 'EOFError': <class 'EOFError'>, 'RuntimeError': <class 'RuntimeError'>, 'RecursionError': <class 'RecursionError'>, 'NotImplementedError': <class 'NotImplementedError'>, 'NameError': <class 'NameError'>, 'UnboundLocalError': <class 'UnboundLocalError'>, 'AttributeError': <class 'AttributeError'>, 'SyntaxError': <class 'SyntaxError'>, 'IndentationError': <class 'IndentationError'>, 'TabError': <class 'TabError'>, 'LookupError': <class 'LookupError'>, 'IndexError': <class 'IndexError'>, 'KeyError': <class 'KeyError'>, 'ValueError': <class 'ValueError'>, 'UnicodeError': <class 'UnicodeError'>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>, 'UnicodeDecodeError': <class 'UnicodeDecodeError'>, 'UnicodeTranslateError': <class 'UnicodeTranslateError'>, 'AssertionError': <class 'AssertionError'>, 'ArithmeticError': <class 'ArithmeticError'>, 'FloatingPointError': <class 'FloatingPointError'>, 'OverflowError': <class 'OverflowError'>, 'ZeroDivisionError': <class 'ZeroDivisionError'>, 'SystemError': <class 'SystemError'>, 'ReferenceError': <class 'ReferenceError'>, 'MemoryError': <class 'MemoryError'>, 'BufferError': <class 'BufferError'>, 'Warning': <class 'Warning'>, 'UserWarning': <class 'UserWarning'>, 'EncodingWarning': <class 'EncodingWarning'>, 'DeprecationWarning': <class 'DeprecationWarning'>, 'PendingDeprecationWarning': <class 'PendingDeprecationWarning'>, 'SyntaxWarning': <class 'SyntaxWarning'>, 'RuntimeWarning': <class 'RuntimeWarning'>, 'FutureWarning': <class 'FutureWarning'>, 'ImportWarning': <class 'ImportWarning'>, 'UnicodeWarning': <class 'UnicodeWarning'>, 'BytesWarning': <class 'BytesWarning'>, 'ResourceWarning': <class 'ResourceWarning'>, 'ConnectionError': <class 'ConnectionError'>, 'BlockingIOError': <class 'BlockingIOError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'ChildProcessError': <class 'ChildProcessError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, 'ConnectionRefusedError': <class 'ConnectionRefusedError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'FileExistsError': <class 'FileExistsError'>, 'FileNotFoundError': <class 'FileNotFoundError'>, 'IsADirectoryError': <class 'IsADirectoryError'>, 'NotADirectoryError': <class 'NotADirectoryError'>, 'InterruptedError': <class 'InterruptedError'>, 'PermissionError': <class 'PermissionError'>, 'ProcessLookupError': <class 'ProcessLookupError'>, 'TimeoutError': <class 'TimeoutError'>, 'open': <built-in function open>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'copyright': Copyright (c) 2001-2023 Python Software Foundation. All Rights Reserved. Copyright (c) 2000 BeOpen.com. All Rights Reserved. Copyright (c) 1995-2001 Corporation for National Research Initiatives. All Rights Reserved. Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. All Rights Reserved., 'credits': Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands for supporting Python development. See www.python.org for more information., 'license': Type license() to see the full license text, 'help': Type help() for interactive help, or help(object) for help about object.}, 'logging': <module 'logging' from '/Users/nick/miniconda3/lib/python3.10/logging/__init__.py'>, 'os': <module 'os' from '/Users/nick/miniconda3/lib/python3.10/os.py'>, 'pgtoolkit': <module 'pgtoolkit' from '/Users/nick/miniconda3/lib/python3.10/site-packages/pgtoolkit/__init__.py'>, 'psycopg2': <module 'psycopg2' from '/Users/nick/miniconda3/lib/python3.10/site-packages/psycopg2/__init__.py'>, 'Callable': <class 'collections.abc.Callable'>, 'Hashable': <class 'collections.abc.Hashable'>, 'Iterable': <class 'collections.abc.Iterable'>, 'Mapping': <class 'collections.abc.Mapping'>, 'MutableMapping': <class 'collections.abc.MutableMapping'>, 'contextmanager': <function contextmanager at 0x7fa8e80d17e0>, 'nullcontext': <class 'contextlib.nullcontext'>, 'wraps': <function wraps at 0x7fa8e811dfc0>, 'DictCursor': <class 'psycopg2.extras.DictCursor'>, 'TracebackType': <class 'traceback'>, 'Any': typing.Any, 'Optional': typing.Optional, 'cfg': {'db': {'service': 'bioinfo_data_psql', 'cursor_factory': <class 'actio_python_utils.database_functions.LoggingCursor'>}, 'data': {'directory': 'data'}, 'loading': {'escape': '\\'"\\'', 'quote': '\\'"\\'', 'sanitize': False}, 'logging': {'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s', 'level': 'INFO', 'names': {'db': 'sql_debug'}, 'loggers_to_ignore': ['parso.cache', 'parso.python.diff']}, 'output': 'output', 'spark': {'codecs': {'glow': 'io.projectglow.sql.util.BGZFCodec'}, 'cores': '*', 'jdbc': '/usr/share/java/postgresql-42.6.0.jar', 'memory': '1g', 'packages': {'excel': 'com.crealytics:spark-excel_2.12:3.3.1_0.18.7', 'glow': 'io.projectglow:glow-spark3_2.12:1.2.1', 'xml': 'com.databricks:spark-xml_2.12:0.15.0'}}}, 'CustomCSVDialect': <class 'actio_python_utils.utils.CustomCSVDialect'>, 'get_csv_fields': <function get_csv_fields at 0x7fa8d8875ab0>, 'rename_dict_keys': <function rename_dict_keys at 0x7fa8d8875120>, 'zopen': <function zopen at 0x7fa8d8875900>, 'logger': <Logger actio_python_utils.database_functions (WARNING)>, 'get_pg_config': <function get_pg_config at 0x7fa8d8876200>, 'split_schema_from_table': <function split_schema_from_table at 0x7fa8d88771c0>, 'savepoint': <function savepoint at 0x7fa8d87fecb0>, 'savepoint_wrapper': <function savepoint_wrapper at 0x7fa8d87fed40>, 'LoggingCursor': <class 'actio_python_utils.database_functions.LoggingCursor'>, 'SavepointCursor': <class 'actio_python_utils.database_functions.SavepointCursor'>, 'replace_dict_values_with_global_definition': <function replace_dict_values_with_global_definition at 0x7fa8d87fedd0>, 'get_db_args': <function get_db_args at 0x7fa8d87ffeb0>, 'DBConnection': <class 'actio_python_utils.database_functions.DBConnection'>, 'connect_to_db': <function connect_to_db at 0x7fa8d87fff40>, '__annotations__': {}}
) – The mapping from which to get replacement values
- Return type:
MutableMapping
[Hashable
,Any
]- Returns:
Updated mapping replacing (key, value) with (key, global_mapping[value]) for appropriate keys