Skip to content

Improve Universe Parameter Type for Python #9447

@AlexCatarino

Description

@AlexCatarino

Expected Behavior

The universe selection parameter is a list and we can access the list semantics

def _fundamental_filter(self, fundamentals: List[Fundamental]) -> List[Symbol]:
    f = fundamentals[0]
    count = len(fundamentals)

Actual Behavior

The universe selection parameter is an iterator (IEnumerable).

def _fundamental_filter(self, fundamentals: Iterable[Fundamental]) -> List[Symbol]:
    f = fundamentals[0]   # syntax error
    count = len(fundamentals)   # syntax error

See QuantConnect/Documentation#2349

Potential Solution

We could fix the stubs to use Iterable instead of List, but I think converting IEnumerable to List is friendlier to users. The user can "fix" on his side using

def _fundamental_filter(self, fundamentals: List[Fundamental]) -> List[Symbol]:
    fundamentals = list(fundamentals)   
    f = fundamentals[0]
    count = len(fundamentals)

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions