Page View Time Series Visualizer test error

Data Analysis with Python Projects

Page View Time Series Visualizer project

I have the code working and passing all but one test which fails with an error. The error happens in the assignment to ‘actual’ from the test:

class DataCleaningTestCase(unittest.TestCase):
    def test_data_cleaning(self):
        actual = int(time_series_visualizer.df.count())
        expected = 1238
        self.assertEqual(actual, expected, "Expected DataFrame count after cleaning to be 1238.")

And the error is:

TypeError: cannot convert the series to <class 'int'>

the return from df.count() is a Pandas Series and if I change the the line to :

 actual = int(time_series_visualizer.df.count()[0])

It passes. Am I missing something or is this an error in the test code?

Hello there,

Could you provide a link to your project, please?

I can’t really change the return type. Here is the code.

The df is set up as a global variable by the starter code and df.count() is a pandas method. It returns an array type (pandas series). I can change the test but these are FCC’s tests and should remain unchanged by me.

Thank you, for pointing this out. I believe the line should be:

actual = int(time_series_visualizer.df.count(numeric_only=True))

Thanks. I put that line in test_module instead.

On second thought, I think the reason you are told to:

Use Pandas to import the data from “fcc-forum-pageviews.csv”. Set the index to the “date” column.

Is so that your df is purely numeric…

So, maybe the tests are correct in expecting numeric values…

OK That works with the test as is, as long as you drop the date column. (Although I am not sure that should be required to test the count after data cleaning. It wouldn’t hurt to add the argument you suggested.)

Thanks

Hello Sky020, I feel your initial suggestion make more sense. Otherwise in draw_bar_plot() session we have to reset the index. Unless this is design intention.

actual = int(time_series_visualizer.df.count(numeric_only=True))

Thanks

Thank you so much for this post and mentioning dropping the date column! I didn’t feel right about changing the test code, either, even though it was frustrating that my code was creating the visualizations but kept from passing by that one error. I’m glad I kept looking for answers because this helped clarify the distinction between numerical and non-numerical data and the right tools to use (Numpy) with each type.