Promptice

Astropy TimeSeries Required Columns Error

astropy__astropy-13033 · cardboard

Astropy TimeSeries Required Columns Error

You are working in the astropy/astropy repository at commit 298ccb478e6bf092953bca67a3d29dc6c35f6752.

Problem

TimeSeries produces a misleading exception when required-column validation fails for objects with more than one required leading column.

For a TimeSeries object that has additional required columns beyond time, removing one of those required columns should produce an error that tells the user which required leading columns were expected and which leading columns were actually found.

Currently, the message assumes time is the only required column. For example, when TimeSeries._required_columns is set to ["time", "flux"] and flux is removed, the error can look like this:

ValueError: TimeSeries object is invalid - expected 'time' as the first columns but found 'time'

That message is confusing because it reports the same visible column on both sides and hides the missing required column.

Reproduction

import numpy as np
from astropy.time import Time
from astropy.timeseries import TimeSeries

time = Time(np.arange(100000, 100003), format="jd")
ts = TimeSeries(time=time, data={"flux": [99.9, 99.8, 99.7]})
ts._required_columns = ["time", "flux"]
ts.remove_column("flux")

Expected Behavior

The exception should identify the full required leading-column prefix and the actual leading columns that were found.

For a two-column requirement like ["time", "flux"], the message should be shaped like:

TimeSeries object is invalid - expected ['time', 'flux'] as the first columns but found ['time', ...]

Keep the existing one-required-column behavior readable. Existing tests around TimeSeries initialization and required columns should continue to pass.

Constraints

  • Do not hard-code this one example.
  • Preserve existing valid TimeSeries behavior.
  • Keep the patch focused on required-column validation and error reporting.
  • Add or update tests if useful, but the hidden grader will apply its own test patch.

Scoring

Your submission is accepted if the hidden fail-to-pass test passes and nearby pass-to-pass tests continue passing. Leaderboards can additionally rank accepted runs by tokens, estimated cost, and wall-clock time.

Container

not started

Visible tests

21

Hidden tests

0

Last run

Not run

21 total0 passed0 failed
1

Test 1

fail to pass

required columns

2

Test 2

pass to pass

empty initialization

3

Test 3

pass to pass

empty initialization invalid

4

Test 4

pass to pass

initialize only time

5

Test 5

pass to pass

initialization with data

6

Test 6

pass to pass

initialize only data

7

Test 7

pass to pass

initialization with table

8

Test 8

pass to pass

initialization missing time delta

9

Test 9

pass to pass

initialization invalid time and time start

10

Test 10

pass to pass

initialization invalid time delta

11

Test 11

pass to pass

initialization with time in data

12

Test 12

pass to pass

initialization n samples

13

Test 13

pass to pass

initialization length mismatch

14

Test 14

pass to pass

initialization invalid both time and time delta

15

Test 15

pass to pass

fold

16

Test 16

pass to pass

fold invalid options

17

Test 17

pass to pass

read time missing

18

Test 18

pass to pass

read time wrong

19

Test 19

pass to pass

read

20

Test 20

pass to pass

periodogram

21

Test 21

pass to pass

periodogram

README.md

astropy/astropy

Loading repository...code-server
Loading...
Workspace Terminal