Skip to content

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

Open
shuxue6662-a11y wants to merge 1 commit into
bashtage:mainfrom
shuxue6662-a11y:codex/fix-panel-missing-index-ids
Open

fix: raise clear errors for missing values in panel index#716
shuxue6662-a11y wants to merge 1 commit into
bashtage:mainfrom
shuxue6662-a11y:codex/fix-panel-missing-index-ids

Conversation

@shuxue6662-a11y

Copy link
Copy Markdown

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 (2ce5503) to head (a0a8d36).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #716   +/-   ##
=======================================
  Coverage   99.54%   99.54%           
=======================================
  Files         101      101           
  Lines       17426    17448   +22     
  Branches     1430     1433    +3     
=======================================
+ Hits        17347    17369   +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.

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

1 participant