Repository navigation
Conversation
The formula parsers build the model matrices with formulaic's na_action="ignore", so that the models drop the observations with missing values themselves. A missing numeric value stays missing, but formulaic encodes a missing value of a categorical variable, C(g) or a column of strings, as zeros in all of its dummy variables, so the observation was kept in the base level without a warning. The same data given as arrays are dropped with a MissingValueWarning since #858. The parsers of the IV, panel and asset pricing models, which the system models and AbsorbingLS use too, now make the rows that formulaic would drop for missing values missing in every column, so that the models drop them as for arrays. The state of stateful transforms is learnt as before. The rows are found by position, since formulaic cannot drop rows of data whose index has duplicate labels. predict with data treats a missing categorical value as missing as well, and formulaic's warning about it is no longer shown. Closes #891
bashtage
force-pushed
the
fix-891-formula-missing-categorical
branch
from
December 3, 2026 11:02
028fd46 to
38b39c0
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #895 +/- ##
========================================
Coverage 99.69% 99.69%
========================================
Files 206 207 +1
Lines 39413 39518 +105
Branches 2537 2542 +5
========================================
+ Hits 39291 39399 +108
+ Misses 52 51 -1
+ Partials 70 68 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #891.
The formula parsers build the model matrices with formulaic's
na_action="ignore", so that the models drop the observations with missing values themselves. A missing numeric value stays missing, but formulaic encodes a missing value of a categorical variable,C(g)or a column of strings, as zeros in all of its dummy variables, so the observation was kept in the base level without a warning. The same data given as arrays are dropped with aMissingValueWarningsince #858. 7.1 behaves the same way as main: with the example in #891, the formula keeps 400 observations anddata.dropna()397.set_missing_rowsinshared/utility.pymakes the rows that formulaic would drop for missing values missing in every column of a model matrix, so the models drop them as for arrays. It asks formulaic for those rows with the model spec andna_action="drop", so the state of stateful transforms such ascenteris learnt as before, and it only runs for formulas with a categorical variable. The rows are found by position, since formulaic raises a length error when it drops rows of data whose index has duplicate labels.AbsorbingLS.from_formulause the IV parser.predictwithdatatreats a missing categorical value as missing too (it is left out, or NaN withmissing=True), and formulaic'sDataMismatchWarningabout it is no longer shown.versionchanged:: 7.2note in the Notes of the 18from_formulamethods, and a note under "Changes that alter results".test_formula_missing_categorical.pychecks that the formula gives the same estimates as the formula on the data without the rows with a missing value (rtol 1e-10), with aMissingValueWarning, for IV2SLS and IVGMM withC(g), a string column and a pandas categorical, AbsorbingLS, PooledOLS, PanelOLS with entity effects, SUR, and LinearFactorModel with and without separate portfolios, and with an index with duplicate labels, and thatpredictgives NaN for the row. All 14 tests fail on main. Each of these changes makes a test fail: locating the rows by label instead of position, showing the warning inpredict, and leaving out either of the asset pricing calls.The pull request with the follow-ups to the merged 7.2 pull requests (#896) also adds a test for #884. The two do not conflict, and the path of
model_matrix_from_specfor a missing value without a new level, which codecov reported on #884, is tested here, since this change alters it.The whole suite passes (pip-pre: Python 3.14, NumPy and pandas development versions), with no new warnings.
🤖 Generated with Claude Code