1.1.8. patsy.design_matrix_builders

patsy.design_matrix_builders(termlists, data_iter_maker, eval_env, NA_action='drop')[source]

Construct several DesignInfo objects from termlists.

This is one of Patsy’s fundamental functions. This function and build_design_matrices() together form the API to the core formula interpretation machinery.

Parameters:
  • termlists – A list of termlists, where each termlist is a list of Term objects which together specify a design matrix.
  • data_iter_maker – A zero-argument callable which returns an iterator over dict-like data objects. This must be a callable rather than a simple iterator because sufficiently complex formulas may require multiple passes over the data (e.g. if there are nested stateful transforms).
  • eval_env – Either a EvalEnvironment which will be used to look up any variables referenced in termlists that cannot be found in data_iter_maker, or else a depth represented as an integer which will be passed to EvalEnvironment.capture(). eval_env=0 means to use the context of the function calling design_matrix_builders() for lookups. If calling this function from a library, you probably want eval_env=1, which means that variables should be resolved in your caller’s namespace.
  • NA_action – An NAAction object or string, used to determine what values count as ‘missing’ for purposes of determining the levels of categorical factors.
Returns:

A list of DesignInfo objects, one for each termlist passed in.

This function performs zero or more iterations over the data in order to sniff out any necessary information about factor types, set up stateful transforms, pick column names, etc.

See formulas for details.

New in version 0.2.0: The NA_action argument.

New in version 0.4.0: The eval_env argument.