datacamp/pythonwhat

SCT fix, "Manipulating Time Series Data in Python" ch3ex2

klmedeiros opened this issue · 4 comments

I have an SCT in "Manipulating Time Series Data in Python" that is complicated. I've opened an issue on the course repo here: https://github.com/datacamp/courses-manipulating-time-series-data-python/issues/30

The provided solution calls for the following piece of code:

# Plot data
data['2010':].plot(title='New York City')
plt.show()

The current SCT was already robust against the different ways you can access the year 2010 in data (with or without .loc):

Ex().test_or(
    has_equal_ast(code="data['2010':].plot(title='New York City')", 
        incorrect_msg="Did you plot the ozone levels since 2010 with the title `'New York City'`?", 
        exact=False),
    has_equal_ast(code="data.loc['2010':].plot(title='New York City')", 
        incorrect_msg="Did you plot the ozone levels since 2010 with the title `'New York City'`?", 
        exact=False)
)

plus an SCT that checks the plt.show() call.

However, student feedback indicated we should also accommodate the following solution (a.k.a. the ol' plt.title() on a separate line):

data.loc['2010':].plot()
plt.title('New York City')

I'm struggling with making this test robust, because so far I'm struggling to check this with methods I know (despite it being similar to the one I just asked for help on, I can't seem to get this one. Something about calling one column of the dataframe makes it just different enough that I'm struggling.)

Thanks for your help and let me know if I can provide more information to assist.

@klmedeiros did you already do any work on this on a branch? If yes, please refer to it here as well.

@filipsch I didn't make much headway on this that seemed worth saving. I tried adding on to the current test_or() statement but it didn't work, so I didn't keep any of it.

@klmedeiros I built an SCT on the SCTs branch with this commit. Like the previous issue, I added explanations. With the 4-fold test_or at the end, all of the following will be accepted:

# solution (title inside)
data['2010':].plot(title = 'New York City')

# title separate
data['2010':].plot()
plt.title('New York City')

# loc, title inside
data.loc['2010':].plot(title = 'New York City')

# loc, title separate
data.loc['2010':].plot()
plt.title('New York City')

These are very tricky examples to figure out. It's good to be exposed to these. I'll keep a reference to these exercises to include them as more advanced examples in the pythonwhat docs.

@filipsch Thank you for looking at this and for writing notes in the commit, those are very helpful for me!