Skip to content

BUG: Ensure std_resid returns named pandas Series for numpy array inputs#844

Open
samanvirajput wants to merge 2 commits into
bashtage:mainfrom
samanvirajput:fix/std-resid-numpy-series
Open

BUG: Ensure std_resid returns named pandas Series for numpy array inputs#844
samanvirajput wants to merge 2 commits into
bashtage:mainfrom
samanvirajput:fix/std-resid-numpy-series

Conversation

@samanvirajput

Copy link
Copy Markdown

Summary

Fixes type inconsistency in ARCHModelResult.std_resid when model input is a numpy array.

Problem

When arch_model() receives a numpy ndarray, std_resid returns a raw numpy array
with no .name attribute instead of a named pandas Series.

Reproducer:

import numpy as np
from arch import arch_model
res = arch_model(np.random.randn(500), vol='GARCH').fit(disp='off')
print(type(res.std_resid))  # <class 'numpy.ndarray'> — should be pd.Series

Fix

Added else branch to wrap numpy output in a named pd.Series with the model index.

Tests

Added 3 tests to arch/tests/univariate/test_base.py covering numpy input,
pandas input (backwards compat), and index preservation.

Motivation

Discovered while computing GARCH residual diagnostics for fat-tail analysis
of Indian equity markets: https://doi.org/10.5281/zenodo.20573035

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.54%. Comparing base (d61843e) to head (efb475d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #844   +/-   ##
=======================================
  Coverage   99.54%   99.54%           
=======================================
  Files          78       78           
  Lines       15817    15846   +29     
  Branches     1294     1294           
=======================================
+ Hits        15745    15774   +29     
  Misses         38       38           
  Partials       34       34           
Flag Coverage Δ
adder 99.50% <100.00%> (+<0.01%) ⬆️
subtractor 99.50% <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.

1 participant