Single-element arrays are read back as scalars from NetCDF files

Open
#211 0 comments 0 reactions 0 assignees View on GitHub

@prathameshfuke is already working on this.

Since Dec 5, 2026.

  • #212 by @prathameshfuke — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start by reading read_from_netcdf, which the issue identifies as returning values[0] for every variable of size 1. Trace how load_events and load_lcurve use its result, then run the NetCDF round-trip examples in the issue. Done means a one-event time remains an array and a one-bin light curve loads successfully.

Written by the indexing model from the issue text.

Description

Describe the bug
A NetCDF file (.nc, the default format) cannot hold a one-element array apart from a scalar: read_from_netcdf returns values[0] for every variable of size 1. So an event list with a single event comes back with time as a scalar, and a light curve with a single bin cannot be loaded at all. The pickle and HDF5 formats round-trip both correctly.

To Reproduce

from stingray import EventList, Lightcurve
from hendrics.io import save_events, load_events, save_lcurve, load_lcurve

save_events(EventList(time=[1.0], gti=[[0, 5]], mjdref=55000.0), "one_ev.nc")
print(load_events("one_ev.nc").time)      # 1.0 (a scalar); with "one_ev.p" it is [1.]

lc = Lightcurve([0.5], [3.0], dt=1, gti=[[0, 1]], mjdref=55000.0)
save_lcurve(lc, "one_lc.nc")
load_lcurve("one_lc.nc")                  # ValueError: time array must be at least 1D

Expected behavior
[1.] and a one-bin light curve, as with the other formats.

Desktop

  • OS: macOS
  • Python version 3.12
  • HENDRICS Version: development from github (main)
Dominant language
Jupyter Notebook
Stars
26
Forks
18
Avg merge
1h 26m
Merged PRs (30d)
2

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/HENDRICS

All issues in StingraySoftware/HENDRICS

Similar issues

More Data Engineering issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.