Skip to content

BUG: Drop observations with missing values for asset pricing models f… - #777

Merged
bashtage merged 1 commit into
mainfrom
lm71-fix-asset-pricing-formula-missing
Oct 12, 2026
Merged

bashtage merged 1 commit into
mainfrom
lm71-fix-asset-pricing-formula-missing

Conversation

@bashtage

Copy link
Copy Markdown
Owner

…rom formulas

TradedFactorModel, LinearFactorModel and LinearFactorModelGMM drop the observations that have a missing value in the portfolios or in the factors, with a MissingValueWarning, when they are made from arrays or data frames. A model made with from_formula raised "ValueError: Error encountered while checking for nulls in port_02" for a missing value in a factor or in a portfolio that the formula names, because the formula parser asked for na_action="raise". A missing value in the data frame passed in portfolios was dropped, so the same data gave an error or an estimate according to where the formula took the variable from.

The parser keeps the missing values now (na_action="ignore") and the model drops the observations with a missing value in any of the portfolios or the factors, in the same way as for arrays. This is the same change that the IV and system formula parsers got.

The tests make the model from the formula, with the portfolios in the formula and in the portfolios argument, and compare the data of the model, and the parameters, with the model made from the data after the rows with a missing value were dropped. They fail without the change.

…rom formulas

TradedFactorModel, LinearFactorModel and LinearFactorModelGMM drop the observations
that have a missing value in the portfolios or in the factors, with a
MissingValueWarning, when they are made from arrays or data frames. A model made with
from_formula raised "ValueError: Error encountered while checking for nulls in `port_02`"
for a missing value in a factor or in a portfolio that the formula names, because the
formula parser asked for na_action="raise". A missing value in the data frame passed in
portfolios was dropped, so the same data gave an error or an estimate according to
where the formula took the variable from.

The parser keeps the missing values now (na_action="ignore") and the model drops the
observations with a missing value in any of the portfolios or the factors, in the same
way as for arrays. This is the same change that the IV and system formula parsers got.

The tests make the model from the formula, with the portfolios in the formula and in the
portfolios argument, and compare the data of the model, and the parameters, with the model
made from the data after the rows with a missing value were dropped. They fail without the
change.
@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.59%. Comparing base (6cbd30b) to head (4c0ab73).
⚠️ Report is 34 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #777      +/-   ##
==========================================
+ Coverage   99.58%   99.59%   +0.01%     
==========================================
  Files         128      128              
  Lines       24188    24454     +266     
  Branches     1809     1822      +13     
==========================================
+ Hits        24087    24355     +268     
+ Misses         40       39       -1     
+ Partials       61       60       -1     
Flag Coverage Δ
adder 99.57% <100.00%> (+0.01%) ⬆️
subtractor 99.57% <100.00%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@bashtage
bashtage merged commit 5c91eb0 into main Oct 12, 2026
24 checks passed
@bashtage
bashtage deleted the lm71-fix-asset-pricing-formula-missing branch October 12, 2026 18:56
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

Successfully merging this pull request may close these issues.

1 participant