You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 like new_mat, = ....)
So instead, I wrote a helper function:
defupdated_design_matrix(design_matrix, data, NA_action='drop'):
"""Shortcut to ``build_design_matrices`` with the builder from ``design_matrix.design_info.builder`` """ifhave_pandasandisinstance(design_matrix, pandas.DataFrame):
return_type='dataframe'else:
return_type='matrix'returnbuild_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 :).
The text was updated successfully, but these errors were encountered:
I found it awkward to use the syntax for using stateful transforms, as shown by the tutorial example:
Two reasons:
[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:
This lets me write this instead:
...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 :).
The text was updated successfully, but these errors were encountered: