Skip to content

mypy: wrong type: ignore code in panel_regression.py breaks pre-commit #852

@anevolbap

Description

@anevolbap

Description

panel_regression.py has two bugs:

  1. Lines 560 and 676 use # type: ignore[attr-defined], but mypy emits [union-attr] errors. The mismatched code means the ignores have no effect, and mypy fails during pre-commit.

  2. plot_unit_effects (line 683) uses float(...) on an xarray result that can have a leftover treated_units dimension, causing TypeError: only 0-dimensional arrays can be converted to Python scalars. This makes test_panel_regression_plot_unit_effects fail on main (Python 3.14).

Root cause

  1. Introduced in commit 1cf3387 (PR Add PanelRegression experiment class for fixed effects estimation #628). self.idata can be None, so accessing .posterior is a union-attr error, not attr-defined.
  2. beta.sel(...).mean(dim=["chain", "draw"]) returns an array with a treated_units dimension, not a scalar.

Fix

  1. Replace [attr-defined] with [union-attr] on lines 560 and 676.
  2. Replace float(...) with .item() on line 683.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions