MLS_Course 2 Week 4 assignment, Error in Ex. 4

Hi, after running the Ex. 4 test code I get the assertation error:
AssertionError: When the target variable is pure, there is no best split to do. Expected -1, got 0

My Ex.4 function:
{moderator edit: code removed}

and the output after running the test code:



Can someone please help me fix this?

Please don’t post your code on the forum. That’s not allowed by the community standards.

A common error in this assignment is if your code doesn’t handle the case where all of the “gain” values are identical.

The function is expected to return the default value of -1 in that situation.