Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the order to check chained functions #370

Open
richierocks opened this issue Jan 10, 2019 · 0 comments
Open

Document the order to check chained functions #370

richierocks opened this issue Jan 10, 2019 · 0 comments
Assignees

Comments

@richierocks
Copy link

In ch3ex6 of "Machine Learning for Time Series in Python", the student has to complete this line of code.

missing_values = prices.isna().sum()

The SCT to check this was

Ex().multi(
    check_correct(
        check_object("missing_values").has_equal_value(), 
        multi(
            check_function("prices.isna.sum", signature=False), 
            check_function("prices.isna")
        )
    )
)

This gives a bad feedback message when the student types a different function to is.na().

For example, the submission

missing_values = prices.isnaxxx().sum()

Results in the feedback

Did you call `prices.isna.sum()`?

This is confusing: it ought to say

Did you call `prices.isna().sum()`?

A partial fix is to perform the checks in reverse order. That is functions should be checked from left to right, not right to left.

Ex().multi(
    check_correct(
        check_object("missing_values").has_equal_value(), 
        multi(
            check_function("prices.isna"),
            check_function("prices.isna.sum", signature=False)
        )
    )
)

In this case, the submission

missing_values = prices.isnaxxx().sum()

gives the feedback

Did you call `prices.isna()`?

It isn't perfect though. The submission

missing_values = prices.isna().sumxxx()

gives the feedback

Did you call `prices.isna.sum()`?

So a custom missing message needs to be provided.

Ex().multi(
    check_correct(
        check_object("missing_values").has_equal_value(), 
        multi(
            check_function("prices.isna"),
            check_function("prices.isna.sum", signature=False, missing_msg = "Did you call `prices.isna().sum()`?")
        )
    )
)

Since this is a subtle problem, I think it needs documenting. Ideally, the feedback message also needs fixing so that parentheses are included where the intermediate element is a function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants