Skip to content

Commit

Permalink
Merge pull request #21 from NREL/dt/improve-error-message
Browse files Browse the repository at this point in the history
Add a better error message
  • Loading branch information
daniel-thom committed Apr 26, 2024
2 parents 7a6c18f + 9b2e8c4 commit fe2295d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/infrasys/time_series_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def add(
raise ISOperationNotAllowed("add_time_series requires at least one component")

ts_type = type(time_series)
if not issubclass(ts_type, TimeSeriesData):
msg = f"The first argument must be an instance of TimeSeriesData: {ts_type}"
raise ValueError(msg)
metadata_type = ts_type.get_time_series_metadata_type()
metadata = metadata_type.from_data(time_series, **user_attributes)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ def test_time_series():
data = range(length)
variable_name = "active_power"
ts = SingleTimeSeries.from_time_array(data, variable_name, time_array)
with pytest.raises(ValueError, match="The first argument must"):
# Test a common mistake.
system.add_time_series(gen1, ts)

system.add_time_series(ts, gen1, gen2)
assert system.has_time_series(gen1, variable_name=variable_name)
assert system.has_time_series(gen2, variable_name=variable_name)
Expand Down

0 comments on commit fe2295d

Please sign in to comment.