Skip to content

TYP: Type the options of lsmr and of the IVSystemGMM estimators with … - #843

Merged
bashtage merged 3 commits into
mainfrom
lm71-typ2-typeddicts-mypy
Oct 15, 2026
Merged

bashtage merged 3 commits into
mainfrom
lm71-typ2-typeddicts-mypy

Conversation

@bashtage

Copy link
Copy Markdown
Owner

…TypedDicts

The options that are passed on with ** had a union of value types, so mypy
checked every parameter of the callee against the whole union and reported
seven errors: five for scipy.sparse.linalg.lsmr in lsmr_annihilate, one for
the weight matrix of IVSystemGMM and one for its covariance.

  • _LSMROptions lists the keyword arguments of lsmr. _options_key takes a
    Mapping, which a TypedDict is.
  • _WeightConfig and _KernelWeightConfig, and _GMMCovConfig and
    _GMMKernelCovConfig, list the options of the weight matrices and of the
    covariances of IVSystemGMM. Only the kernel estimators take kernel,
    bandwidth and optimal_bw, so the kernel estimator is constructed directly,
    and the others through GMM_W_EST and GMM_COV_EST as before.

The public signatures are unchanged, and so are the estimators that are
constructed and the options they receive.

…TypedDicts

The options that are passed on with ** had a union of value types, so mypy
checked every parameter of the callee against the whole union and reported
seven errors: five for scipy.sparse.linalg.lsmr in lsmr_annihilate, one for
the weight matrix of IVSystemGMM and one for its covariance.

- _LSMROptions lists the keyword arguments of lsmr. _options_key takes a
  Mapping, which a TypedDict is.
- _WeightConfig and _KernelWeightConfig, and _GMMCovConfig and
  _GMMKernelCovConfig, list the options of the weight matrices and of the
  covariances of IVSystemGMM. Only the kernel estimators take kernel,
  bandwidth and optimal_bw, so the kernel estimator is constructed directly,
  and the others through GMM_W_EST and GMM_COV_EST as before.

The public signatures are unchanged, and so are the estimators that are
constructed and the options they receive.
find_constant is annotated to return an int, but returned a NumPy integer.
The demeaning paths of PanelOLS returned the integer 0 as the weighted mean
of the dependent variable of a model without a constant, where the return
type is a float64 array; it is now the 0-d array np.array(0.0). fit uses
that mean only if the model has a constant, so the results do not change.
Run mypy with pandas-stubs and scipy-stubs on pushes to main and on pull
requests. The result is informational: new releases of mypy and of the
stubs often add errors, so a failure does not fail the check. It adds a
warning annotation with the number of errors, and the log lists them.
@bashtage
bashtage merged commit 1c3fe26 into main Oct 15, 2026
12 of 23 checks passed
@bashtage
bashtage deleted the lm71-typ2-typeddicts-mypy branch October 15, 2026 11:58
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