Error Programming Assignment Exercise 1

Im receiving the following error:
Error: Data-type mismatch.
4 Tests passed
1 Tests failed

AssertionError Traceback (most recent call last)
in ()
1 ### test cell ex1: you cannot edit this cell
----> 2 proportion_treated_test(proportion_treated)

~/work/W1A1/public_tests.py in proportion_treated_test(target)
59 ]
60
—> 61 multiple_test(test_cases, target)
62
63

~/work/W1A1/test_utils.py in multiple_test(test_cases, target)
121 print(‘\033[92m’, success," Tests passed")
122 print(‘\033[91m’, len(test_cases) - success, " Tests failed")
→ 123 raise AssertionError(“Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for proportion_treated. Check your equations and avoid using global variables inside the function.

Can someone please help me understand what Im doing wrong. Thank you

Im pretty sure the formula is right and my output matches the expected output. Hopefully someone can help out!

I’m confused then. I thought from the thread title there was an error being thrown. The linked thread describes the same error, and a work around. Just matching the numeric value doesn’t seem to be enough for this unit test. Maybe I misunderstood.

No you’re right. Im not really good at understanding errors.

The error message means your code in “proportion_treated()” doesn’t pass some of the tests.

So click on the thread linked above, read the explanation provided by the mentor there, give it a try.

Im still confused. Seems so simple.

Hi @Tayler-Frances_Chapm and @ai_curious,

Can you share your code so that we can direct you in the right direction?

Samuel

Here’s the relevant section of the post I linked above …

Can you check the data type of the return value according to the error message? For example, you can check with type().

If the data type is float, can you wrap it with np.float64() and execute the code cell again?

In the docstring of the function proportion_treated(), the return value is stated as float, but when I checked the test function proportion_treated_test(), it seemed that the test case is prepared with np.float64() data type.

In addition, you can refer to the code of proportion_treated_test() in public_tests.py in the Lab files of your Coursera workspace.

my emphasis added

The workaround seems to be to coerce the type returned from the function from plain float to float64. Seems worth a try, no?

NOtE: that thread is almost 5 months old and this seems to be only the second time anyone is reporting this specific problem, so maybe there is something in common with these two implementations that causes the problem. Still, if the numeric value is equal and the only issue is the precision / type, it’s an easy workaround.

1 Like