Less awkward API for using simple stateful transforms?
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 990
- Forks
- 106
- Avg merge
- 7d 34m
- Merged PRs (30d)
- 1
Description
I found it awkward to use the syntax for using stateful transforms, as shown by the tutorial example:
>>> build_design_matrices([mat.design_info.builder], new_data)[0]
Two reasons:
- Understanding the full expression entails a deep dive into patsy's API.
- As a code reviewer, I also worry when I see things like
[0]at the end of an expression because it looks like data might be being thrown away. (I suppose one solution to this is to do explicit assignment likenew_mat, = ....)
So instead, I wrote a helper function:
def updated_design_matrix(design_matrix, data, NA_action='drop'):
"""Shortcut to ``build_design_matrices`` with the builder from
``design_matrix.design_info.builder``
"""
if have_pandas and isinstance(design_matrix, pandas.DataFrame):
return_type = 'dataframe'
else:
return_type = 'matrix'
return build_design_matrices([design_matrix.design_info.builder], data,
NA_action, return_type, design_matrix.dtype)[0]
This lets me write this instead:
>>> updated_design_matrix(mat, new_data)
...which looks much closer to the "high level" syntax.
Does something like this belong in core patsy?
Note: we will need a similarly named (but probably not the same) function to handle the "update" syntax of . (note #28).
P.S. In case it isn't obvious, it has been a pleasure for me to discover and use patsy over the past few weeks :).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the tutorial example using build_design_matrices and the proposed updated_design_matrix helper in the issue. Read the surrounding patsy API and consider how the separate update syntax in issue #28 affects the design. Done means an agreed, maintainable high-level API and corresponding implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100