Skip to content

MAINT: Cleanup dead code, address FIXMEs, and fix Kalman filter prediction corner case #9740 #9741

Open
un1u3 wants to merge 1 commit intostatsmodels:mainfrom
un1u3:statsmodels-cleanup-and-fixes
Open

MAINT: Cleanup dead code, address FIXMEs, and fix Kalman filter prediction corner case #9740 #9741
un1u3 wants to merge 1 commit intostatsmodels:mainfrom
un1u3:statsmodels-cleanup-and-fixes

Conversation

@un1u3
Copy link
Contributor

@un1u3 un1u3 commented Jan 13, 2026

PR for Issue #9740

This PR performs a broad cleanup of the statsmodels codebase to improve maintainability and addresses a specific corner case in Kalman filter predictions. Key changes include removing dead code, implementing missing convergence warnings, and refining diffuse initialization logic.

Detailed Changes

1. Bug Fixes & Improvements

  • Kalman Filter (kalman_filter.py): Fixed a corner case where dynamic/out-of-sample predictions were incorrectly initialized if the filter hadn't exited the diffuse phase. Now uses Initialization.from_components with the diffuse covariance when predicted_diffuse_state_cov is non-zero.
  • SARIMA Warnings (innovations.py): Added ConvergenceWarning to innovations_mle when the nonlinear optimizer fails (success=False).

2. Dead Code Removal (Library)

  • regressionplots.py: Removed internal helper _partial_regression which was unused and redundant.

3. Test Suite Cleanup

  • test_glm.py: Removed extensive commented-out test blocks relying on obsolete rpy2 infrastructure.
  • test_regression.py: Removed multiple unused check_confidenceintervals methods and associated FIXME comments.
  • test_var.py: Removed the unused CheckVAR class and broken generate_var functions.
  • test_data.py: Removed the commented-out TestDates class.

4. Documentation & Annotation

  • kernels.py: Removed a stale FIXME in aitchison_aitken_cdf. The logic was verified to be correct for joint CDF definitions of encoded discrete variables.

Verification Plan

  • Manual Inspection: Verified that all removed code has no callers in the current repository.
  • State Space Logic: Verified that predict now correctly passes Pinf when initializing the forecast model during the diffuse phase.
  • Local Testing: Individual syntax and logic checks were performed; full test suite execution was limited due to environment/versioning constraints with pytest.

@un1u3
Copy link
Contributor Author

un1u3 commented Jan 22, 2026

@bashtage any updates on this PR

Copy link
Member

@ChadFulton ChadFulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall seems probably fine. I'm not totally sure how much benefit there is to removing these unused tests. On balance, I suspect cleaning things up is better than keeping around things "in case they're useful", given the relatively limited maintenance hours these days.

On the Kalman filter prediction corner case - what you have looks reasonable to me, but I'd be curious if everything works okay if the situation actually arises. I think the diffuse component is typically centered at zero, so it probably wouldn't cause a problem with the predicted means, though I would assume we would get inf or NaN in the confidence intervals.

Would you be able to add a unit test for the case where we predict prior to the end of diffuse initialization? I think that if you used an UnobservedComponents model with a seasonal component of 12 periods and exact diffuse initialization, then it would still be in the diffuse regime if you had fewer than 12 periods of data, and then called predict.

num_levels = Xi_vals.size
for x in Xi_vals:
if x <= x_u: # FIXME: why a comparison for unordered variables?
if x <= x_u:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably shouldn't just remove a FIXME without changing anything

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.

2 participants