Skip to content

Enhance formula parsing#1222

Open
leostimpfle wants to merge 28 commits intomasterfrom
feat/1213-multipart
Open

Enhance formula parsing#1222
leostimpfle wants to merge 28 commits intomasterfrom
feat/1213-multipart

Conversation

@leostimpfle
Copy link
Copy Markdown
Collaborator

@leostimpfle leostimpfle commented Mar 6, 2026

To do

  • The ^ operator is currently reserved for interactions of fixed effects (see here). This is necessary only because the operator expects a number on the right side (e.g., X^2). We could avoid this if we decided to use a different symbol for fixed effect interactions (e.g., f1:f2).
  • Validate that the stateful_transform works correctly on the captured context (see here and related to Enable formulaic to parse custom data transforms from context #769).
  • Set transforms consistently across project to address Bug: predict() method fails with new data and pyfixest special syntax - i(), C(), var1^var2 operators #684
  • Clean up tests to remove deprecated syntax (Y+Y2 ~X1 should be replaced with sw(Y, Y2) ~ X1; Y ~ X1 | X2 ~ Z2 with Y ~ X1 + [X2 ~ Z2])
  • formulaic.formula.Formula.required_variables calls ast.parse(factor.expr, mode="eval") which might fail if variable names are not valid Python expressions (e.g., 0_X2_1). This, however, is necessary to account for transformed variables (e.g., Y ~ C(X2) + [X2 ~ Z2]).
  • Guard against specification of multiple multistage parts. For example, we do not support Y ~ [X1 ~ Z1] + [X2 ~ Z2].
  • Guard against specification of more than two formula parts (we only allow a single second part for fixed effects).

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 96.17225% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pyfixest/estimation/formula/parse.py 91.57% 8 Missing ⚠️
Flag Coverage Δ
core-tests 71.25% <91.34%> (+0.24%) ⬆️
test-r-core 52.74% <91.86%> (+0.14%) ⬆️
test-r-extended 19.27% <32.53%> (+0.52%) ⬆️
test-r-fixest 40.01% <91.38%> (+0.17%) ⬆️
tests-extended ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pyfixest/did/did2s.py 89.42% <100.00%> (+0.10%) ⬆️
pyfixest/estimation/FixestMulti_.py 82.01% <ø> (ø)
pyfixest/estimation/formula/__init__.py 100.00% <100.00%> (ø)
pyfixest/estimation/formula/model_matrix.py 95.23% <100.00%> (-0.08%) ⬇️
...stimation/formula/transforms/factor_interaction.py 95.83% <100.00%> (ø)
...ation/formula/transforms/fixed_effects_encoding.py 100.00% <100.00%> (ø)
pyfixest/estimation/formula/transforms/misc.py 100.00% <100.00%> (ø)
pyfixest/estimation/formula/utils.py 97.50% <100.00%> (+0.20%) ⬆️
pyfixest/estimation/models/feols_.py 87.44% <100.00%> (-4.77%) ⬇️
pyfixest/estimation/models/feols_compressed_.py 80.23% <100.00%> (ø)
... and 3 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leostimpfle leostimpfle marked this pull request as ready for review March 7, 2026 07:41
@leostimpfle leostimpfle requested a review from s3alfisc March 7, 2026 07:41
@leostimpfle
Copy link
Copy Markdown
Collaborator Author

@s3alfisc The core changes to formula parsing are now ready. Feel free to have a look and let me know any comments. I'll continue to work through the to-dos listed above.

@s3alfisc
Copy link
Copy Markdown
Member

s3alfisc commented Mar 7, 2026

Just took a quick look and was thinking - maybe it would be best if we'd do a pair review for this through a call? I would make sure to spent some time with it before to come prepared 😃

@leostimpfle
Copy link
Copy Markdown
Collaborator Author

Very happy to jump on a call!

leostimpfle and others added 10 commits March 7, 2026 15:56
# Conflicts:
#	pyfixest/estimation/formula/model_matrix.py
#	pyfixest/estimation/formula/utils.py
When PyCharm launches Python directly (not via pixi run), CONDA_PREFIX is
not set. maturin requires it to locate the environment for develop builds.
Also add pixi-pycharm to project dependencies.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants