Error in Test Module

I wanted to see if anyone else has run into this issue with this assignment. When I run my code through the test module it returns a single error stating: TypeError: unsupported operand types for list and list.
The reason it is returning this error is because it is trying to perform “assertAlmostEqual” on 2 lists which as far as I know can only be performed on integers/floats not lists of integers/floats.
Am I mistaken? How can I fix this?

This is the testing code:

def test_race_count(self):
actual = self.data[‘race_count’].tolist()
expected = [27816, 3124, 1039, 311, 271]
self.assertAlmostEqual(actual, expected, msg=“Expected race count values to be [27816, 3124, 1039, 311, 271]”)

This is my code that it is testing:

race_count = df.groupby(‘race’)[(‘race’)].count()

Your browser information: Google Chrome

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36.

Challenge: Demographic Data Analyzer

Link to the challenge:

You are correct that assertAlmostEqual may have problems with comparing lists that are not equal, but within some limit that would consider them as almost equal. However it’s still able to confirm when they are indeed equal.

I see. The list my code is returning is the same as the list they are testing except the values are in a different order. Could this be why its having this error?

ie.
The list they are testing is : [27816, 3124, 1039, 311, 271]
My list is : [311, 1039, 3124, 271, 27816]

Yes, that would be a reason.

Great, thank you! I appreciate the help!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.