Skip to content

Commit

Permalink
Massive refactoring of build.py to merge DesignMatrixBuilder into Des…
Browse files Browse the repository at this point in the history
…ignInfo

Notable changes:
- DesignInfo now exposes lots more metadata about how exactly different
  factors and terms are coded.
- In fact, it exposes enough more metadata that you can now reconstruct
  a design matrix entirely from a DesignInfo, so DesignMatrixBuilder
  becomes redundant and is removed in favor of DesignInfo.
- DesignInfo's constructor is very different; in particular, removed the
  option of specifying terms as strings, which was only useful for
  interoperability with competing formula libraries. Four years later, no
  such competitors have appeared, so I can't be bothered to keep maintaining
  this. Will re-add later if someone actually wants to use it.

This versions works and passes tests, but a bunch more tests need to be
added.

This fixes #61, and sets us up to implemented pickling support (#26, #67).
  • Loading branch information
njsmith committed Jun 14, 2015
1 parent 1139e3a commit b420d7f
Show file tree
Hide file tree
Showing 7 changed files with 760 additions and 515 deletions.
36 changes: 33 additions & 3 deletions doc/API-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,35 @@ Design metadata
di.term_slices
.. attribute:: factor_infos

A dict mapping factor objects to :class:`FactorInfo` objects
providing information about each factor. Like :attr:`terms`,
this may be None.

.. ipython:: python
di.term_slices
.. attribute:: term_codings

An :class:`~collections.OrderedDict` mapping each :class:`Term`
object to a list of :class:`SubtermInfo` objects which together
describe how this term is encoded in the final design
matrix. Like :attr:`terms`, this may be None.

.. ipython:: python
di.term_codings
.. attribute:: builder

A :class:`DesignMatrixBuilder` object that can be used to
generate more design matrices of this type (e.g. for
prediction). May be None.
In versions of patsy before 0.4.0, this returned a
``DesignMatrixBuilder`` object which could be passed to
:func:`build_design_matrices`. Starting in 0.4.0,
:func:`build_design_matrices` now accepts :class:`DesignInfo`
objects directly, and writing ``f(design_info.builder)`` is now a
deprecated alias for simply writing ``f(design_info)``.

A number of convenience methods are also provided that take
advantage of the above metadata:
Expand All @@ -120,8 +144,14 @@ Design metadata

.. automethod:: slice

.. automethod:: subset

.. automethod:: from_array

.. autoclass:: FactorInfo

.. autoclass:: SubtermInfo

.. autoclass:: DesignMatrix

.. automethod:: __new__
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# General information about the project.
project = u'patsy'
copyright = u'2011-2013, Nathaniel J. Smith'
copyright = u'2011-2015, Nathaniel J. Smith'

import sys
print "python exec:", sys.executable
Expand Down
Loading

0 comments on commit b420d7f

Please sign in to comment.