power_color() mutates input power array and raises IndexError when freqs_to_exclude reaches frequency bounds

Open Beginner friendly
#1,052 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@Rohan-Dedhia is already working on this.

Since Dec 5, 2026.

  • #1053 by @Rohan-Dedhia — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
80/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python
Domain
data

Research direction

Start by reading stingray.power_colors.power_color() and inspect how it builds the exclusion mask and finds the boundary indices. Reproduce both cases from the issue: an input array that is mutated and an exclusion range extending past the final frequency. Done means the caller's array stays unchanged and both boundary cases complete without an IndexError; the issue names no test file.

Written by the indexing model from the issue text.

Description

Description of the Bug

In stingray.power_colors.power_color(), when freqs_to_exclude is provided:

  1. In-place input mutation: power = np.asanyarray(power) does not copy when power is already a NumPy array, so power[frequency_mask] = np.mean([power[idx0], power[idx1]]) mutates the caller's power array in-place.
  2. Boundary IndexError: When an excluded range extends to or past the upper edge of frequency (for example, freqs_to_exclude=[10.0, 20.0] on a spectrum ending at 16.0), np.searchsorted(frequency, [f0, f1]) returns idx1 == len(frequency), and indexing power[idx1] raises IndexError.
Steps/Code to Replicate the Bug
import numpy as np
from stingray.power_colors import power_color

f = np.linspace(0.004, 16.0, 200)
p = f.copy()
p_orig = p.copy()

# 1. Input array is mutated in-place
power_color(f, p, freqs_to_exclude=[1.0, 2.0])
print("input mutated?", not np.array_equal(p, p_orig))

# 2. Boundary exclusion raises IndexError
power_color(f, p_orig, freqs_to_exclude=[10.0, 20.0])
Expected Results

power_color() should not mutate the caller's power array, and freqs_to_exclude ranges reaching or exceeding the frequency boundaries should be handled cleanly without raising IndexError.

Actual Results
  1. input mutated? True
  2. power_color(f, p_orig, freqs_to_exclude=[10.0, 20.0]) raises:
IndexError: index 200 is out of bounds for axis 0 with size 200
Dominant language
Python
Stars
230
Forks
200
Avg merge
3d 16h
Merged PRs (30d)
22

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from StingraySoftware/stingray

All issues in StingraySoftware/stingray

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.