The test modules sometimes appear to ignore valid answers. I understand that in order for projects to be graded programmatically there needs to be certain limits on what counts as a valid answer, but the occasionally leads to cases where identical visual output is considered invalid. This is especially problematic when the output is a plot. For example, in the “data analysis with python” project “medical data visualizer”, the following code produces a bar chart that is identical to the target bar chart, but it causes errors in the code evaluation (the code itself runs without errors, it is the evaluation of the code in the test module that causes the errors). The only difference between the plot produced by this code and the target plot is the y axis, but that value isn’t checked.
def draw_cat_plot(): # Create DataFrame for cat plot using `pd.melt` using just the values from 'cholesterol', 'gluc', 'smoke', 'alco', 'active', and 'overweight'. df_cat = df.melt(id_vars=["cardio"],value_vars=['active', 'alco', 'cholesterol', 'gluc', 'overweight', 'smoke']) # Group and reformat the data to split it by 'cardio'. Show the counts of each feature. You will have to rename one of the columns for the catplot to work correctly. temp=df_cat.copy() df_cat = df_cat.groupby(["cardio",'variable']) df_cat=df_cat["value"].value_counts() # Draw the catplot with 'sns.catplot()' fig=sns.catplot(data=temp, x="variable",kind="count",hue="value", col="cardio") fig.savefig('catplot.png') # Do not modify the next two lines return fig
I suspect that the issue is that I am “supposed” to use the summary data returned by pandas functions (which I included only on a hunch that it might help fix the issue, it didn’t), instead of creating the plot whole-cloth using builtin seaborn functions, but given that the resulting plots are identical, that FreeCodeCamp doesn’t actually provide instruction on using Seaborn (the videos were on matplotlib, so there is no hint as to what the “correct” answer should look like), and that using the seaborn code makes for a more elegant solution, the provided solution really should be considered valid.
On top of that, the test_module code is clearly cut and paste from another module, and so has “vestigial” code chunks. Frankly, that’s just sloppy for public facing code.