Page View Time Series Visualizer - 3 plots created - test errors

Tell us what’s happening:

I get the 3 images for test cases but receiving 9 errors:

:face_with_monocle:5 errors like this one:

======================================================================
ERROR: test_bar_plot_number_of_bars (test_module.BarPlotTestCase)

Traceback (most recent call last):
File “/home/runner/fcc-time-series-visualizer/test_module.py”, line 38, in setUp
self.fig = time_series_visualizer.draw_bar_plot()
File “/home/runner/fcc-time-series-visualizer/time_series_visualizer.py”, line 39, in draw_bar_plot
df.reset_index(inplace=True)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 4849, in reset_index
new_obj.insert(0, name, level_values)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 3618, in insert
self._mgr.insert(loc, column, value, allow_duplicates=allow_duplicates)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/internals/managers.py”, line 1147, in insert
raise ValueError(f"cannot insert {item}, already exists")
ValueError: cannot insert level_0, already exists

:face_with_monocle:1 like this:

ERROR: test_data_cleaning (test_module.DataCleaningTestCase)

Traceback (most recent call last):
File “/home/runner/fcc-time-series-visualizer/test_module.py”, line 8, in test_data_cleaning
actual = int(time_series_visualizer.df.count(numeric_only=True))
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/series.py”, line 129, in wrapper
raise TypeError(f"cannot convert the series to {converter}")
TypeError: cannot convert the series to <class ‘int’>

:face_with_monocle:and 3 like this:

ERROR: test_line_plot_title (test_module.LinePlotTestCase)

Traceback (most recent call last):
File “/home/runner/fcc-time-series-visualizer/test_module.py”, line 15, in setUp
self.ax = self.fig.axes[0]
TypeError: ‘function’ object is not subscriptable

Don´t want the code, just help to understand and find the solution by myself!

Thanks!
Your code so far


Your browser information:

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: Page View Time Series Visualizer

Link to the challenge:

UPDATE!!! I´m receiving same error:

Matplotlib created a temporary config/cache directory at /config/matplotlib because the default path (/tmp/matplotlib-hcmi1uw5) is not a writable directory; it is highly recommended to set the MPLCONFIGDIR environment variable to a writable directory, in particular to speed up the import of Matplotlib and to better support multiprocessing.
…EEEEE…

ERROR: test_bar_plot_number_of_bars (test_module.BarPlotTestCase)

Traceback (most recent call last):
File “/home/runner/fcc-time-series-visualizer/test_module.py”, line 37, in setUp
self.fig = time_series_visualizer.draw_bar_plot()
File “/home/runner/fcc-time-series-visualizer/time_series_visualizer.py”, line 32, in draw_bar_plot
df.reset_index(inplace=True)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 4849, in reset_index
new_obj.insert(0, name, level_values)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 3618, in insert
self._mgr.insert(loc, column, value, allow_duplicates=allow_duplicates)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/internals/managers.py”, line 1147, in insert
raise ValueError(f"cannot insert {item}, already exists")
ValueError: cannot insert level_0, already exists

======================================================================
ERROR: test_box_plot_labels (test_module.BoxPlotTestCase)

Traceback (most recent call last):
File “/home/runner/fcc-time-series-visualizer/test_module.py”, line 68, in setUp
self.fig = time_series_visualizer.draw_box_plot()
File “/home/runner/fcc-time-series-visualizer/time_series_visualizer.py”, line 59, in draw_box_plot
df_box.reset_index(inplace=True)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 4849, in reset_index
new_obj.insert(0, name, level_values)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 3618, in insert
self._mgr.insert(loc, column, value, allow_duplicates=allow_duplicates)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/internals/managers.py”, line 1147, in insert
raise ValueError(f"cannot insert {item}, already exists")
ValueError: cannot insert level_0, already exists

======================================================================
ERROR: test_box_plot_number (test_module.BoxPlotTestCase)

Traceback (most recent call last):
File “/home/runner/fcc-time-series-visualizer/test_module.py”, line 68, in setUp
self.fig = time_series_visualizer.draw_box_plot()
File “/home/runner/fcc-time-series-visualizer/time_series_visualizer.py”, line 59, in draw_box_plot
df_box.reset_index(inplace=True)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 4849, in reset_index
new_obj.insert(0, name, level_values)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 3618, in insert
self._mgr.insert(loc, column, value, allow_duplicates=allow_duplicates)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/internals/managers.py”, line 1147, in insert
raise ValueError(f"cannot insert {item}, already exists")
ValueError: cannot insert level_0, already exists

======================================================================
ERROR: test_box_plot_number_of_boxs (test_module.BoxPlotTestCase)

Traceback (most recent call last):
File “/home/runner/fcc-time-series-visualizer/test_module.py”, line 68, in setUp
self.fig = time_series_visualizer.draw_box_plot()
File “/home/runner/fcc-time-series-visualizer/time_series_visualizer.py”, line 59, in draw_box_plot
df_box.reset_index(inplace=True)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 4849, in reset_index
new_obj.insert(0, name, level_values)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 3618, in insert
self._mgr.insert(loc, column, value, allow_duplicates=allow_duplicates)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/internals/managers.py”, line 1147, in insert
raise ValueError(f"cannot insert {item}, already exists")
ValueError: cannot insert level_0, already exists

======================================================================
ERROR: test_box_plot_titles (test_module.BoxPlotTestCase)

Traceback (most recent call last):
File “/home/runner/fcc-time-series-visualizer/test_module.py”, line 68, in setUp
self.fig = time_series_visualizer.draw_box_plot()
File “/home/runner/fcc-time-series-visualizer/time_series_visualizer.py”, line 59, in draw_box_plot
df_box.reset_index(inplace=True)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 4849, in reset_index
new_obj.insert(0, name, level_values)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/frame.py”, line 3618, in insert
self._mgr.insert(loc, column, value, allow_duplicates=allow_duplicates)
File “/opt/virtualenvs/python3/lib/python3.8/site-packages/pandas/core/internals/managers.py”, line 1147, in insert
raise ValueError(f"cannot insert {item}, already exists")
ValueError: cannot insert level_0, already exists


Ran 11 tests in 5.996s

FAILED (errors=5)

Could someone please help me?
:upside_down_face:

New update!

The issue is with the “reset_index”:

df_box.reset_index(inplace=True)

df.reset_index(inplace=True)

:grimacing:

Could someone help me to fix this?

Nevermind! I just put the index_reset outside each function and it solve the issue!

:grinning:

I went through this issue as well.

I think the error occurred in your project because you created the df['date'] column in the draw_bar_plot() function.

Because the column was created in the original df and not a copy df.reset_index(inplace=True) could not create the df['date'] column since it already existed.

From what I read in the docs. The df.reset_index(inplace=True) takes the index and adds it as a column before resetting it. I think you could set it to df.reset_index(inplace=True, drop=True) and it might also solve the issue. the drop would just get rid of the old index without adding it as a column. ( But I guess that would be touching what we are technically not meant to touch)

Maybe call the dates using df.index.year or make a copy DataFrame. The index up until the reset later on in the draw_box_plot() Function holds all the parsed dates.

My forked project didn’t include that first df.reset_index(inplace=True) Not sure about that one being included in the original.

I hope this info helps. I can 100% relate to being stuck and this project gave me a lot of trouble. I probably have some mistakes in here since I am still figuring this out myself LOL. We are in this together I suppose.

Cheers!

1 Like