Module matchops.constructor

module containing generic resources for constructing dataframes used in data operations.

Classes

class AddColumn (new_column_name: str, source_columns: list[str], apply_function: collections.abc.Callable[..., str], axis: int = 1)

defines a new column built from existing columns in a dataframe using the .apply() pandas function with axis=1.

Class variables

var apply_function : collections.abc.Callable[..., str]
var axis : int
var new_column_name : str
var source_columns : list[str]
class DataFrameConstructor (constructor: collections.abc.Callable[..., pandas.core.frame.DataFrame] = <function read_csv>, converters: dict[str, collections.abc.Callable[..., str]] = <factory>, add_columns: list[AddColumn] = <factory>, kwargs: dict[str, typing.Any] = <factory>, post_process: collections.abc.Callable[[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame] | None = None)

stores pandas methods, arguments, and data transformations required to construct dataframes from arbitrary datasources from a common api.

Attributes

constructor : Callable[…, pd.DataFrame]
pandas method used to construct the dataframe
converters : dict[str, Callable[…, str]]
dictionary of column names and functions to apply to the column values during construction.
add_columns : list[AddColumn]
list of AddColumn dataclasses defining new columns to be added to the dataframe.
kwargs : dict[str, Any]
keyword arguments passed to constructor().
post_process : Callable[[pd.DataFrame], pd.DataFrame] | None
function to apply to the dataframe after construction.

Class variables

var add_columns : list[AddColumn]
var converters : dict[str, collections.abc.Callable[..., str]]
var kwargs : dict[str, typing.Any]
var post_process : collections.abc.Callable[[pandas.core.frame.DataFrame], pandas.core.frame.DataFrame] | None

Methods

def get_frame(self, data: Any, *, static_cols: collections.abc.Mapping[str, str] | None = None, reqd: collections.abc.Sequence[str] = ()) ‑> pandas.core.frame.DataFrame

Construct a dataframe using the supplied data

Args

data : Any
data to be passed to constructor

KwArgs

static_cols
a mapping representing a name and static value to be added as a column to the dataframe
reqd
list of column names that must be present in the dataframe. if not present, add the column with a default value of "".