Skip to content

Conversation

@sackio
Copy link

@sackio sackio commented Dec 24, 2025

Summary

The np.where() function can return read-only array views. When these arrays are modified in-place (e.g., in fvg() join_consecutive loop and swing_highs_lows() deduplication), it causes ValueError: buffer source array is read-only errors.

This fix adds .copy() after np.where() calls for arrays that are later modified in-place:

  • fvg(): fvg, top, bottom arrays
  • swing_highs_lows(): swing_highs_lows array

Reproduction

This error occurs when using the library with VectorBT Pro, which provides OHLC data as read-only NumPy arrays for performance.

Test plan

  • Tested with VectorBT Pro integration
  • Existing unit tests should pass (no behavior change, only writability fix)

The np.where() function can return read-only array views. When these
arrays are modified in-place (e.g., in fvg() join_consecutive loop and
swing_highs_lows() deduplication), it causes 'buffer source array is
read-only' errors.

This fix adds .copy() after np.where() calls for arrays that are later
modified in-place:
- fvg: fvg, top, bottom arrays
- swing_highs_lows: swing_highs_lows array
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