Skip to content

"Set" classes are not iterable #65

Description

@awendelin-work

The Set classes, ExperimentSet, TraceSet, ConfigurationParameterDescriptorSet, ConfigurationSet, ConfigurationSourceSet and OutputDescriptorSet are not usable by themselves as collections.

This gives you access patterns like:

from tsp.trace_set import TraceSet

traces = TraceSet([{"name": "trace0"}, {"name": "trace1"}])

for trace in traces.traces:
    print(t.name)
# trace0
# trace1

print(len(traces.traces))
# 2

This is especially inconvenient when working with experiments, since to loop over traces, you must do:

for t in experiment.traces.traces

We could make the classes easier to work with by making them implement collection interfaces.

This would give you the following access patterns instead:

from tsp.trace_set import TraceSet

traces = TraceSet([{"name": "trace0"}, {"name": "trace1"}])

for trace in traces:
    print(t.name)
# trace0
# trace1

print(len(traces))
# 2

See example in this commit.

__getitem__ could be implemented as well to allow indexing with integers (traces[0]), but it is not implemented for Python sets, so it would make the "Set" classes look less like sets.

If this kind of functionality is wanted, I can help provide patches.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions