Data Analysis with Python Projects - Medical Data Visualizer | Empty Text Objects Causing Test Fail

Tell us what’s happening:
I’ve passed all but one of the automated tests for the heatmap case, which checks the contents of the text in the figure to ensure the correlation results are correct with this line:

actual = [text.get_text() for text in self.ax.get_default_bbox_extra_artists() if isinstance(text, mpl.text.Text)]

The problem is that there are 3 blank text objects in my seaborn heatmap for some reason that are causing the test to fail:

Text(0.5, 1, ''), Text(0.0, 1, ''), Text(1.0, 1, '')
======================================================================
FAIL: test_heat_map_values (test_module.HeatMapTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/boilerplate-medical-data-visualizer/test_module.py", line 47, in test_heat_map_values
    self.assertEqual(actual, expected, "Expected different 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']

First list contains 3 additional elements.
First extra element 91:
''

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

----------------------------------------------------------------------
Ran 4 tests in 8.712s

FAILED (failures=1)

Your code so far

My heatmap drawing code is:

# Draw the heatmap with 'sns.heatmap()'
    sns.set(font_scale=.5)
    sns.heatmap(corr, mask=mask, annot=True, linewidth=.25, fmt='.1f', square=True, axes=ax)
    print (ax.get_default_bbox_extra_artists())

which produces:

image

I can’t figure out where the additional text objects are coming from or how to get rid of them though.

EDIT: Additional Detail

I tried setting annot=False and still got the empty text objects:

self.assertEqual(actual, expected, "Expected different values in heat map.")
AssertionError: Lists differ: ['', '', ''] != ['0.0', '0.0', '-0.0', '0.0', '-0.1', '0.5'[615 chars]0.1']

In fact, this time, they were the only strings I got, which suggests they aren’t annotations.

Your browser information:

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

Challenge: Data Analysis with Python Projects - Medical Data Visualizer

Link to the challenge:

I’ve seen that while debugging and I’m not sure those Text objects are the problem (they could be though). There was an old dependency problem that caused a problem with 3 elements from ~2 years ago that is fixable by updating all the project dependencies. Post a repl (replit.com) of your code for debugging so that we can determine if it is the old dependency problem or something else elsewhere in your code.

Apologies for the delayed response, I sent a reply with a link to my repl on Saturday but it fell afoul of the spam filter and is currently awaiting review

Hi again,

I just wanted to check this so I went in and modified the test slightly to:

def test_heat_map_values(self):
        actual = [text.get_text() for text in self.ax.get_default_bbox_extra_artists() if isinstance(text, mpl.text.Text)][:-3]

only adding the slice at the end to remove the last 3 empty text objects. Doing that resulted in the test passing:

Ran 4 tests in 23.588s

OK

So it certainly seems like they’re at fault. Could you explain how to update the project dependencies so I can try that?

The tests are working; I’ve verified them on other versions of this project within the last week. You don’t need to drop 3 items of that array as you could be erroneously adding those three items in your code somewhere else (possibly even in a seemingly unrelated part of the code).

You can update dependencies with poetry or the packages tool in replit. There are several threads about dependency problems in the python data analysis packages in the forums.

Unfortunately, without a link to the code, there is really no way to isolate the problem.

I just tried to send the link to my replit again but it was instantly hidden for staff review, is there another way I can provide it?

If you know how to construct the replit URL, you can find my code. The project name is:

boilerplate-medical-data-visualizer

and my username is:

mcgeochd

You have the dependency problem, just like this here.

I’m not sure about your link posting problem though.

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