Skip to content

BUG: Reject negative bandwidths in panel and IV kernel estimators - #887

Merged
bashtage merged 1 commit into
bashtage:mainfrom
leninworld:fix-negative-bandwidth
Dec 1, 2026
Merged

bashtage merged 1 commit into
bashtage:mainfrom
leninworld:fix-negative-bandwidth

Conversation

@leninworld

Copy link
Copy Markdown
Contributor

This PR fixes issue #886.

Fixes #886

The panel and IV kernel estimators document bandwidth as non-negative but accepted a negative value. With the Bartlett and Parzen kernels the result was that of bandwidth=0; with the quadratic spectral kernel the standard errors could be very different (in the issue's example, -3 shrinks them by roughly 30-40%).

They now raise ValueError: bandwidth must be non-negative., the message the system and asset-pricing estimators already use:

  • DriscollKraay, ACCovariance and FamaMacBethCovariance
  • the IV KernelCovariance
  • the IV GMM KernelWeightMatrix (at construction) and IVGMMCovariance with cov_type="kernel"

bandwidth=None, 0 and positive values behave as before. A NaN bandwidth is not covered by this change.

Verification:

  • the new linearmodels/tests/test_negative_bandwidth.py: the 12 negative-bandwidth cases fail on main and pass here; the 12 bandwidth=0 cases pass on both
  • pytest linearmodels/tests: 23724 passed, 2473 skipped, 47 xfailed (macOS, Python 3.12)
  • flake8, black --check, isort --check, ruff check on the changed files pass; mypy reports the same errors as main

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.69%. Comparing base (00528bd) to head (81814d1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #887   +/-   ##
=======================================
  Coverage   99.69%   99.69%           
=======================================
  Files         202      203    +1     
  Lines       38871    38941   +70     
  Branches     2501     2503    +2     
=======================================
+ Hits        38752    38822   +70     
  Misses         51       51           
  Partials       68       68           
Flag Coverage Δ
adder 99.68% <100.00%> (+<0.01%) ⬆️
subtractor 99.68% <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 commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Thanks. Makes sense to check.

@bashtage
bashtage merged commit f480402 into bashtage:main Dec 1, 2026
15 checks passed
@leninworld

Copy link
Copy Markdown
Contributor Author

Thanks. Makes sense to check.

Thank you @bashtage

bashtage added a commit to echuq/linearmodels that referenced this pull request Dec 3, 2026
…ir contributors

bashtage#864 fixed the two-way clustered covariance of the IV models for float
and string cluster labels, which 7.1 got wrong or rejected, and bashtage#878
made the clustered covariances faster, but neither had a 7.2 note. The
note of the negative bandwidth fix cites bashtage#887 as well as bashtage#886, and the
contributors of the pull requests merged since the list was started are
thanked: echuq, AryanRG, soodoku, WeiLiuu and leninworld.
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.

BUG: Panel and IV kernel estimators accept a negative bandwidth

2 participants