Skip to content

Commit

Permalink
Merge 36d6a73 into aa6f673
Browse files Browse the repository at this point in the history
  • Loading branch information
PGijsbers committed Feb 10, 2017
2 parents aa6f673 + 36d6a73 commit 0244a2a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 10 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,16 @@ def test_get_by_name():
"""Assert that the Operator class returns operators by name appropriately"""
assert Operator.get_by_name("SelectKBest").__class__ == TPOTSelectKBest

def test_operator_inheritors_order():
"""Assert that the Operations.inheritors() always return the same order."""
same_order = []
for _ in range(10):
operators1 = map(lambda op: op.__name__, Operator.inheritors())
operators2 = map(lambda op: op.__name__, Operator.inheritors())
ordered = all([op1 == op2 for (op1, op2) in zip(operators1, operators2)])
same_order.append(ordered)

assert all(same_order)

def test_gen():
"""Assert that TPOT's gen_grow_safe function returns a pipeline of expected structure"""
Expand Down
9 changes: 5 additions & 4 deletions tpot/operators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,17 @@ def inheritors(cls):
Returns
-------
operators: set
Set of all discovered operators that inherit from the base class
List of all discovered operators that inherit from the base class
"""
operators = set()
operators = list()

# Search two levels deep and report leaves in inheritance tree
for operator_type in cls.__subclasses__():
for operator in operator_type.__subclasses__():
operators.add(operator()) # Instantiate class and append

operators.append(operator()) # Instantiate class and append

operators = sorted(operators, key=lambda op: op.__name__)
return operators

@classmethod
Expand Down

0 comments on commit 0244a2a

Please sign in to comment.