Hi all,
I’m done with the Demographic Data Analyzer test except for one error which - I think - is related to the test-module.py code, and not to the code I have written. But I could use help understanding what’s going on and how to proceed!
One of the project requirements is to produce a Pandas series containing names of races in the dataset and a count of individuals in the dataset for each race. The prompt and my line of code are below:
# How many of each race are represented in this dataset? This should be a Pandas series with race names as the index labels.
race_count = df.groupby('race').size()
The test module code creates a list from the resultant series and compares to a list of the expected values:
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]")
Here’s the problem. When that code runs, an error is thrown saying that assertAlmostEqual can’t take two lists as arguments!
ERROR: test_race_count (test_module.DemographicAnalyzerTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-demographic-data-analyzer/test_module.py", line 11, in test_race_count
self.assertAlmostEqual(actual, expected, msg="Expected race count values to be [27816, 3124, 1039, 311, 271]")
File "/usr/lib/python3.8/unittest/case.py", line 943, in assertAlmostEqual
diff = abs(first - second)
TypeError: unsupported operand type(s) for -: 'list' and 'list'
So I believe that something like assertCountEqual is required instead. But - needless to say - I don’t want to myself edit the test-module.py code to pass the test. What should I do?