Lightcurve slicing raises IndexError when the slice bounds are outside the light curve

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

Maintainers usually reply within 2 days

@prathameshfuke is already working on this.

Since Dec 5, 2026.

  • #1055 by @prathameshfuke — open

Assessment

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

Research direction

Start by reading Lightcurve.__getitem__ and compare its handling of slice bounds with NumPy array slicing. Reproduce the reported case with lc[3:100] and lc[-100:4]; done means both return the same clipped bins as slicing lc.counts without raising IndexError.

Written by the indexing model from the issue text.

Description

Description of the Bug

Lightcurve.__getitem__ uses the raw slice start/stop to read self.time[stop - 1], so a slice that goes past either end raises IndexError. NumPy arrays, and StingrayTimeseries, clip such slices.

Steps/Code to Replicate the Bug
import numpy as np
from stingray import Lightcurve

lc = Lightcurve(np.arange(10) + 0.5, np.arange(10.) + 1, dt=1)
lc[3:100]
Expected Results

The last 7 bins, as for lc.counts[3:100] (same for lc[-100:4]).

Actual Results
IndexError: index 99 is out of bounds for axis 0 with size 10

Stingray main at e96829ef, Python 3.12, NumPy 2.x.

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.