It’s late at night and this test is giving me a headache, any advice or help is appreciated.
FAIL: test_box_plot_number_of_boxes (test_module.BoxPlotTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/workspace/boilerplate-page-view-time-series-visualizer/test_module.py", line 117, in test_box_plot_number_of_boxes
self.assertEqual(actual, expected, "Expected four boxes in box plot 1")
AssertionError: 4.666666666666667 != 4 : Expected four boxes in box plot 1
def draw_box_plot():
# Prepare data for box plots
df_box = df.copy()
df_box.reset_index(inplace=True)
df_box['year'] = df_box['date'].dt.year
df_box['month'] = df_box['date'].dt.strftime('%b')
# Ensure the 'value' column is explicitly converted to float
df_box['value'] = df_box['value'].astype(float)
# Prepare year-wise data
years = sorted(df_box['year'].unique())
year_data = [df_box[df_box['year'] == year]['value'] for year in years]
# Debugging: Print year data
for year, data in zip(years, year_data):
print(f"Year: {year}, Data Length: {len(data)}")
# Prepare month-wise data
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
month_data = [df_box[df_box['month'] == month]['value'] for month in months]
# Draw box plots using matplotlib directly
fig, axs = plt.subplots(1, 2, figsize=(18, 6))
# Year-wise Box Plot
axs[0].boxplot(year_data, labels=years)
axs[0].set_title('Year-wise Box Plot (Trend)')
axs[0].set_xlabel('Year')
axs[0].set_ylabel('Page Views')
# Month-wise Box Plot
axs[1].boxplot(month_data, labels=months)
axs[1].set_title('Month-wise Box Plot (Seasonality)')
axs[1].set_xlabel('Month')
axs[1].set_ylabel('Page Views')
# Save image and return fig
fig.savefig('box_plot.png')
return fig