Skip to content

Comments

fix: handle numpy integer types in PeriodRange.__getitem__#173

Merged
knutdrand merged 1 commit intomasterfrom
fix/CLIM-455-validation-numpy-int
Feb 4, 2026
Merged

fix: handle numpy integer types in PeriodRange.__getitem__#173
knutdrand merged 1 commit intomasterfrom
fix/CLIM-455-validation-numpy-int

Conversation

@knutdrand
Copy link
Collaborator

Summary

  • Fix AttributeError when validating backtest data with missing values
  • PeriodRange.__getitem__ now accepts np.integer types in addition to Python int
  • This allows np.flatnonzero indices to work correctly when reporting validation errors

Root Cause

The validation code in create-backtest-with-data endpoint uses np.flatnonzero(isnan) to find indices of NaN values. These indices are numpy.int64, not Python int. When used to index PeriodRange, the isinstance(item, int) check failed, falling through to slice handling code which tried to access item.step.

Test plan

  • Added unit test for PeriodRange.__getitem__ with numpy integer types
  • Verified fix works with the failing request JSON via Docker endpoint

CLIM-455

The validation code in create-backtest-with-data uses np.flatnonzero
which returns numpy.int64 values. When these are used to index into
PeriodRange, the isinstance(item, int) check failed because numpy.int64
is not a Python int, causing an AttributeError when trying to access
item.step on the numpy integer.

This fix extends the type check to also accept np.integer types.

CLIM-455
@knutdrand knutdrand marked this pull request as ready for review February 4, 2026 14:24
@knutdrand knutdrand merged commit 2e2b769 into master Feb 4, 2026
6 checks passed
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