Skip to content

Commit

Permalink
fixup! refactor: rework timeseries parameter indexing API
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed May 27, 2024
1 parent 3dc6c8b commit ec9f34b
Showing 1 changed file with 34 additions and 34 deletions.
68 changes: 34 additions & 34 deletions src/parameter_indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,44 +317,44 @@ struct MultipleParametersGetter{T <: IsIndexerTimeseries, G, I} <:
AbstractParameterGetIndexer
getters::G
timeseries_idx::I
end

function MultipleParametersGetter(getters)
has_timeseries_indexers = any(getters) do g
is_indexer_timeseries(g) == IndexerTimeseries()
end
has_non_timeseries_indexers = any(getters) do g
is_indexer_timeseries(g) == IndexerNotTimeseries()
end
if has_timeseries_indexers && has_non_timeseries_indexers
throw(ArgumentError("Cannot mix timeseries and non-timeseries indexers in `$MultipleParametersGetter`"))
end
indexer_type = if has_timeseries_indexers
getters = as_timeseries_indexer.(getters)
timeseries_idx = indexer_timeseries_index(first(getters))
IndexerTimeseries
elseif has_non_timeseries_indexers
getters = as_not_timeseries_indexer.(getters)
timeseries_idx = nothing
IndexerNotTimeseries
else
timeseries_idx = indexer_timeseries_index(first(getters))
IndexerBoth
end
function MultipleParametersGetter(getters)
has_timeseries_indexers = any(getters) do g
is_indexer_timeseries(g) == IndexerTimeseries()

Check warning on line 324 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L322-L324

Added lines #L322 - L324 were not covered by tests
end
has_non_timeseries_indexers = any(getters) do g
is_indexer_timeseries(g) == IndexerNotTimeseries()

Check warning on line 327 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L326-L327

Added lines #L326 - L327 were not covered by tests
end
if has_timeseries_indexers && has_non_timeseries_indexers
throw(ArgumentError("Cannot mix timeseries and non-timeseries indexers in `$MultipleParametersGetter`"))

Check warning on line 330 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L329-L330

Added lines #L329 - L330 were not covered by tests
end
indexer_type = if has_timeseries_indexers
getters = as_timeseries_indexer.(getters)
timeseries_idx = indexer_timeseries_index(first(getters))
IndexerTimeseries
elseif has_non_timeseries_indexers
getters = as_not_timeseries_indexer.(getters)
timeseries_idx = nothing
IndexerNotTimeseries

Check warning on line 339 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L332-L339

Added lines #L332 - L339 were not covered by tests
else
timeseries_idx = indexer_timeseries_index(first(getters))
IndexerBoth

Check warning on line 342 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L341-L342

Added lines #L341 - L342 were not covered by tests
end

if indexer_type != IndexerNotTimeseries &&
!allequal(indexer_timeseries_index(g) for g in getters)
if indexer_type == IndexerTimeseries
throw(ArgumentError("All parameters must belong to the same timeseries"))
else
indexer_type = IndexerNotTimeseries
timeseries_idx = MixedTimeseriesIndexes(indexer_timeseries_index.(getters))
getters = as_not_timeseries_indexer.(getters)
end
if indexer_type != IndexerNotTimeseries &&

Check warning on line 345 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L345

Added line #L345 was not covered by tests
!allequal(indexer_timeseries_index(g) for g in getters)
if indexer_type == IndexerTimeseries
throw(ArgumentError("All parameters must belong to the same timeseries"))

Check warning on line 348 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L347-L348

Added lines #L347 - L348 were not covered by tests
else
indexer_type = IndexerNotTimeseries
timeseries_idx = MixedTimeseriesIndexes(indexer_timeseries_index.(getters))
getters = as_not_timeseries_indexer.(getters)

Check warning on line 352 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L350-L352

Added lines #L350 - L352 were not covered by tests
end

return new{indexer_type, typeof(getters), typeof(timeseries_idx)}(
getters, timeseries_idx)
end

return MultipleParametersGetter{indexer_type, typeof(getters), typeof(timeseries_idx)}(

Check warning on line 356 in src/parameter_indexing.jl

View check run for this annotation

Codecov / codecov/patch

src/parameter_indexing.jl#L356

Added line #L356 was not covered by tests
getters, timeseries_idx)
end

const AtLeastTimeseriesMPG = Union{
Expand Down

0 comments on commit ec9f34b

Please sign in to comment.