Miscellaneous Utility Functions

This module just contains utility functions that don’t directly fit anywhere else. You shouldn’t need to tinker with these.

pg_utils.util.position_of_positional_arg(arg_name, fcn)[source]

Finds the index of a function’s named positional arguments that has a specific name. For example:

In [1]: def foo(x, y, z, w=1, q=None): pass

In [2]: _position_of_positional_arg("y", foo)
Out[2]: 1

In [3]: _position_of_positional_arg("z", foo)
Out[3]: 2

In [4]: _position_of_positional_arg("w", foo)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

<...snip...>

ValueError: Argument 'w' not found as a named positional argument of function foo
Parameters:
  • arg_name (str) – The name of the parameter to search for.
  • fcn – A function whose parameters we will search.
Returns:

The index (if it exists).

Return type:

int

Raises:

ValueError: If arg_name isn’t the name of any named positional argument of fcn.

pg_utils.util.process_schema_and_conn(f)[source]

This decorator does the following (which is needed a few times in the Table class):

  • Standardizes the table_name and schema parameters (the first of which must be positional and named, and the latter of which must be a keyword parameter). In particular, if table_name == "foo.bar", then schema is replaced with "foo" and table_name with "bar". If the table name is not qualified with a schema, then both schema and table_name are left alone.
  • If no conn keyword argument is given (or if it’s None), then that keyword argument is replaced with a fresh Connection object.
Raises:
  • ValueError – if mismatching schemas are found in both schema and table_name
  • ValueError – if we can’t parse the table name (ie more than one occurrence of ".").
pg_utils.util.seaborn_required(f)[source]

This decorator makes sure that seaborn is imported before the function is run.