Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rigorously handle 0d/1d interaction in factor values #24

Open
njsmith opened this issue Sep 29, 2013 · 0 comments
Open

Rigorously handle 0d/1d interaction in factor values #24

njsmith opened this issue Sep 29, 2013 · 0 comments

Comments

@njsmith
Copy link
Member

njsmith commented Sep 29, 2013

Some things that would be nice:

build_design_matrices([builder], {"x": 1, "y": [1, 2, 3]})

should probably broadcast x against y -- very nice for prediction! (But if it were {"x": [1], "y": [1, 2, 3]} then that should be an error.)

build_design_matrices([builder], {"x": 1, "a": "a0"})

should not be an error. (Right now, scalar numerics get converted up to columns via atleast2d_column_default, but scalar categoricals are just an error.)

And also, that last one should perhaps return a 1d ndarray or Series, not a 2d ndarray or DataFrame. (And this also applies when the data passed in is a Series, e.g. a row from a DataFrame.) The motivation is that this would make

pred_x = build_design_matrices([builder], {"x": 1, "a": "a0"})
dot(pred_x, betas)

give you a scalar when betas.ndim == 1 or a 1d vector in the multivariate case where betas.ndim == 2. But

pred_x = build_design_matrices([builder], {"x": [1], "a": ["a0"]})
dot(pred_x, betas)

would give you a 1d vector when betas.ndim == 1 or a 2d vector in the multivariate case.

This would definitely simplify patsy's prediction code!

A concern is that just starting to return 1d design "matrices" (or Series with return_type="dataframe", oops) might break existing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant