Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure filter occurs before sort #204

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions nrel/hive/util/dict_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def iterate_sim_coll(
) -> Tuple[V, ...]:
"""
helper to iterate through a collection on the SimulationState with optional
sort key function and filter function
sort key function and filter function. performs filter before sort if both
are provided.

:param collection: collection on SimulationState
:type collection: immutables.Map[K, V]
Expand All @@ -108,11 +109,12 @@ def iterate_sim_coll(
:rtype: Tuple[V, ...]
"""

vals = DictOps.iterate_vals(collection, sort_key)
if filter_function:
return tuple(filter(filter_function, vals))
entities = immutables.Map({k: v for k, v in collection.items() if filter_function(v)})
else:
return vals
entities = collection
vals = DictOps.iterate_vals(entities, sort_key)
return vals

@classmethod
def add_to_dict(cls, xs: immutables.Map[K, V], obj_id: K, obj: V) -> immutables.Map[K, V]:
Expand Down