Skip to content

fix: raise clear errors for missing values in panel index - #716

Merged
bashtage merged 1 commit into
bashtage:mainfrom
shuxue6662-a11y:codex/fix-panel-missing-index-ids
Sep 15, 2026
Merged

bashtage merged 1 commit into
bashtage:mainfrom
shuxue6662-a11y:codex/fix-panel-missing-index-ids

Conversation

@shuxue6662-a11y

Copy link
Copy Markdown
Contributor

Description

PanelData.entity_ids / PanelData.time_ids return the raw pandas MultiIndex codes. When the panel index contains missing values (NaN), pandas encodes them as -1, so the ids silently contain negative values and panel_structure_stats() fails later with a generic numpy error:

ValueError: 'list' argument must have no negative elements

This PR makes the failure mode explicit:

  • entity_ids and time_ids now raise a ValueError explaining that the panel index contains missing values (NaN), which are not supported.
  • panel_structure_stats() now validates that ids are non-negative and raises a clear ValueError naming the statistic and the cause, protecting every call site.

Motivation and Context

Fixes #614.

How Has This Been Tested?

  • Added regression tests for missing entity/time index labels and for negative ids in panel_structure_stats.
  • pytest linearmodels/tests/panel/test_data.py -> 185 passed.
  • black --check, isort --check-only, flake8, and ruff check are clean on the changed files.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.54%. Comparing base (a75eed2) to head (83545f2).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #716   +/-   ##
=======================================
  Coverage   99.54%   99.54%           
=======================================
  Files         101      101           
  Lines       17428    17450   +22     
  Branches     1430     1433    +3     
=======================================
+ Hits        17349    17371   +22     
  Misses         29       29           
  Partials       50       50           
Flag Coverage Δ
adder 99.53% <100.00%> (+<0.01%) ⬆️
subtractor 99.53% <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 force-pushed the codex/fix-panel-missing-index-ids branch from a0a8d36 to 83545f2 Compare September 15, 2026 12:51
@bashtage
bashtage merged commit d079828 into bashtage:main Sep 15, 2026
18 of 20 checks passed
@bashtage

Copy link
Copy Markdown
Owner

Thanks.

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.

panel_structure_stats() returns a generic numpy error if ids are negative

2 participants