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

model_spec.transform_state bugged when formula is not correctly written #165

Closed
arturodcv opened this issue Dec 4, 2023 · 1 comment · Fixed by #166
Closed

model_spec.transform_state bugged when formula is not correctly written #165

arturodcv opened this issue Dec 4, 2023 · 1 comment · Fixed by #166
Assignees
Labels
bug Something isn't working

Comments

@arturodcv
Copy link

arturodcv commented Dec 4, 2023

In case the given formula is not correctly written i.e., with extra or forgotten spaces then the transform_state dictionary keys does not match and the dictionary results in {}. Here is an example:

`import numpy as np
import pandas as pd
from formulaic import Formula

df = pd.DataFrame({
'y': np.linspace(1,5,10),
'x': np.linspace(0,1,10),
})

# Formula well written
y, X = Formula('y ~ bs(x, df=4) ').get_model_matrix(df)
print(X.model_spec.dict["transform_state"])
`

results in {'bs(x, df=4)': {'lower_bound': 0.0, 'upper_bound': 1.0, 'knots': [0.0, 0.0, 0.0, 0.0, 0.5, 1.0, 1.0, 1.0, 1.0]}} while

`# Formula not well written (note the whitespaces)

y, X = Formula('y ~ bs( x, df = 4) ').get_model_matrix(df)
print(X.model_spec.dict["transform_state"])
`

results in {}

I am using Formulaic version 0.6.6

@matthewwardrop matthewwardrop self-assigned this Dec 5, 2023
@matthewwardrop matthewwardrop added the bug Something isn't working label Dec 5, 2023
@matthewwardrop
Copy link
Owner

Thanks for reporting @arturodcv ! This is indeed a subtle bug that I likely wouldn't have caught. Will get it straighted out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants