Medical Data Visualizer : Heatmap values test fail

My code is running fine and executing properly as well when I run it independently on a Jupyter notebook. But when the test module is run on it I get the following failure:


self.assertEqual(actual, expected, “Expected differnt values in heat map.”)
AssertionError: Lists differ: ['0.0[607 chars] ‘0.2’, ‘0.1’, ‘0.1’, ‘-0.0’, ‘0.0’, ‘-0.0’, ‘0.1’] != ['0.0[607 chars] ‘0.2’, ‘0.1’, ‘0.1’, ‘-0.0’, ‘0.0’, ‘-0.0’, ‘0.1’, ‘’, ‘’, ‘’]

Second list contains 3 additional elements.
First extra element 91:
‘’

Diff is 989 characters long. Set self.maxDiff to None to see it. : Expected differnt values in heat map.

Ran 4 tests in 8.711s

FAILED (failures=1)


As can be seen here, the failure is due to the absence of the 3 blanks in the list, which are not present in the result from my code. What could be the reason for this? I have scoured the forum for this but it seems no one else has encountered this issue before.
As far as I can tell, the lists are the contents of the correlation matrix, and for there to be blanks present in the matrix, the df.corr() has to return a blank, am I correct?
What might have I done wrong in my code?
I saw a few other codes here on the forum, and mine was pretty much identical , for generating the heatmap.
Here is my code:

# Generate a mask for the upper triangle
    mask = np.triu(corr)
    

    # Set up the matplotlib figure
    fig, ax = plt.subplots(figsize=(11, 9))

    # Draw the heatmap with 'sns.heatmap()'
    sns.heatmap(corr, mask=mask, 
                cbar_kws={"shrink": 0.5}, center=0.0, 
                annot=True, fmt=".1f", 
                linewidths=.5, vmax=0.32, vmin=-0.16)
    


    # Do not modify the next two lines
    fig.savefig('heatmap.png')
    return fig

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

Challenge: Medical Data Visualizer

Link to the challenge:

This is because using different matplotlib version. Or rather getting different output due to using different version. In poetry.lock file, change version for matplotlib to the 3.2.2 and re-run repl. Test should be passing now.

3 Likes

Thanks a lot. That fixed it!