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

[WIP] Update pythonwhat is_instance documentation #382

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,32 @@ Check Multiple Choice
"That's a clown who likes burgers.",
"Correct! Head over to the next exercise!"])

Recommended approach for testing train test splits
Copy link
Member

@hermansje hermansje Jun 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a link to this section.

That section should mention that the names of these arguments are not fixed, something like:

Note that the *args argument, while common does not need to be named args. Pythonwhat expexts the real argument name. Use inspect.signature as done above to know the argument name.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code::

# solution
# Perform the train-test split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain where this function comes from (just mention library).


# sct
Ex().check_correct(
multi(
check_object("X_train").has_equal_value(),
check_object("X_test").has_equal_value(),
check_object("y_train").has_equal_value(),
check_object("y_test").has_equal_value()
),
check_function("sklearn.model_selection.train_test_split").multi(
check_args(["arrays", 0]).has_equal_value("Did you correctly pass in the feature variable to `train_test_split()`?"),
check_args(["arrays", 1]).has_equal_value("Did you correctly pass in the target variable to `train_test_split()`?"),
check_args(["options", "test_size"]).has_equal_value("Did you specify the correct train test split?"),
check_args(["options", "random_state"]).has_equal_value("Don't change the `random_state` argument we set for you.")
)
)


Check import
~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions pythonwhat/checks/check_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def is_instance(state, inst, not_instance_msg=None):
used to 'zoom in' on the object of interest.

Args:
inst (class): The class that the object should have.
inst (str): The class that the object should have as a string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation is correct according to the implementation and this test:

def test_is_instance(stu_code, passes):

Copy link
Contributor Author

@TimSangster TimSangster Jun 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, found what you mean, going to look into it

not_instance_msg (str): When specified, this overrides the automatically generated message in case
the object does not have the expected class.
state (State): The state that is passed in through the SCT chain (don't specify this).
Expand All @@ -220,7 +220,7 @@ def is_instance(state, inst, not_instance_msg=None):

# Verify the class of arr
import numpy
Ex().check_object('arr').is_instance(numpy.ndarray)
Ex().check_object('arr').is_instance('numpy.ndarray')
"""

state.assert_is(["object_assignments"], "is_instance", ["check_object"])
Expand Down