Alcides Fonseca

40.197958, -8.408312

Hidden Bug: Python class as definition

While preparing geneticengine to participate in the SRBench 2024 run, I was getting None out of a constructor:


def PredictorWrapper(BaseEstimator): def __init__(self, ind: tuple[str, str]): self.ind = ind

def predict(self, X): _, data = self.prepare_inputs(X) return forward_dataset(self.ind0, data) def to_sympy(self): return self.ind1

def mk_estimator(x): print(f“x={x}”) p = PredictorWrapper(x) print(f“p={p}”) return p

Outputting:

x=('np.log(np.power(dataset[:,1], 10.0))', 'log((x1 ** 10.0))')
p=None


Have you found the bug? It took me probably around 1 hour, mainly because I trusted myself too much (and there many other things going on in the code). If you still haven’t found the bug, check the first 3 characters of the code snippet. A function with only other functions inside returns None.