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

Aperta
#211 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@prathameshfuke ci sta già lavorando.

Dal 5/12/2026.

  • #212 di @prathameshfuke — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
data

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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)
Lingua principale
Jupyter Notebook
Stelle
26
Fork
18
Merge medio
1h 26m
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di StingraySoftware/HENDRICS

Tutte le issue di StingraySoftware/HENDRICS

Issue simili

Altre issue su Data Engineering

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.