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

MNT enable doctests #57

Merged
merged 2 commits into from
Aug 19, 2022
Merged

MNT enable doctests #57

merged 2 commits into from
Aug 19, 2022

Conversation

adrinjalali
Copy link
Member

@adrinjalali adrinjalali commented Jul 25, 2022

This PR makes sure we run doctests as well as normal tests.

doctests are the code we have in our documentation, such as docstrings' examples.

cc @skops-dev/maintainers

Fixes #58

@adrinjalali adrinjalali changed the title MNT enable doctests [WIP] MNT enable doctests Jul 26, 2022
@adrinjalali
Copy link
Member Author

Going to address #58 in this PR as well. I'll ping when ready.

@adrinjalali adrinjalali changed the title [WIP] MNT enable doctests MNT enable doctests Aug 19, 2022
@@ -194,7 +194,7 @@ class Card:
>>> from sklearn.linear_model import LogisticRegression
>>> from skops import card
>>> X, y = load_iris(return_X_y=True)
>>> model = LogisticRegression(random_state=0).fit(X, y)
>>> model = LogisticRegression(solver="liblinear", random_state=0).fit(X, y)
Copy link
Member Author

Choose a reason for hiding this comment

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

This removes the convergence warning.

Copy link
Collaborator

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

In general, this LGTM and can be merged.

When testing this, I had, however, a problem I have not encountered yet. When running

HF_HUB_TOKEN=... pytest

I get this error:

_______________________________________________________________________________________________________________ ERROR collecting docs/auto_examples/plot_hf_hub.py _______________________________________________________________________________________________________________
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/runner.py:338: in from_call
    result: Optional[TResult] = func()
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/runner.py:369: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/doctest.py:545: in collect
    module = import_path(self.path, root=self.config.rootpath)
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/pathlib.py:556: in import_path
    raise ImportPathMismatchError(module_name, module_file, path)
E   _pytest.pathlib.ImportPathMismatchError: ('plot_hf_hub', '/home/vinh/work/forks/skops/docs/_build/html/_downloads/2032e07369644f9c24738f10000c87c8/plot_hf_hub.py', PosixPath('/home/vinh/work/forks/skops/docs/auto_examples/plot_hf_hub.py'))
_____________________________________________________________________________________________________________ ERROR collecting docs/auto_examples/plot_model_card.py _____________________________________________________________________________________________________________
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/runner.py:338: in from_call
    result: Optional[TResult] = func()
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/runner.py:369: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/doctest.py:545: in collect
    module = import_path(self.path, root=self.config.rootpath)
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/pathlib.py:556: in import_path
    raise ImportPathMismatchError(module_name, module_file, path)
E   _pytest.pathlib.ImportPathMismatchError: ('plot_model_card', '/home/vinh/work/forks/skops/docs/_build/html/_downloads/72a607ff8c7821f84fc735322deb04db/plot_model_card.py', PosixPath('/home/vinh/work/forks/skops/docs/auto_examples/plot_model_card.py'))
____________________________________________________________________________________________________________________ ERROR collecting examples/plot_hf_hub.py ____________________________________________________________________________________________________________________
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/runner.py:338: in from_call
    result: Optional[TResult] = func()
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/runner.py:369: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/doctest.py:545: in collect
    module = import_path(self.path, root=self.config.rootpath)
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/pathlib.py:556: in import_path
    raise ImportPathMismatchError(module_name, module_file, path)
E   _pytest.pathlib.ImportPathMismatchError: ('plot_hf_hub', '/home/vinh/work/forks/skops/docs/_build/html/_downloads/2032e07369644f9c24738f10000c87c8/plot_hf_hub.py', PosixPath('/home/vinh/work/forks/skops/examples/plot_hf_hub.py'))
__________________________________________________________________________________________________________________ ERROR collecting examples/plot_model_card.py __________________________________________________________________________________________________________________
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/runner.py:338: in from_call
    result: Optional[TResult] = func()
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/runner.py:369: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/doctest.py:545: in collect
    module = import_path(self.path, root=self.config.rootpath)
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/pathlib.py:556: in import_path
    raise ImportPathMismatchError(module_name, module_file, path)
E   _pytest.pathlib.ImportPathMismatchError: ('plot_model_card', '/home/vinh/work/forks/skops/docs/_build/html/_downloads/72a607ff8c7821f84fc735322deb04db/plot_model_card.py', PosixPath('/home/vinh/work/forks/skops/examples/plot_model_card.py'))
____________________________________________________________________________________________________________________ ERROR collecting scripts/clean_skops.py _____________________________________________________________________________________________________________________
scripts/clean_skops.py:15: in <module>
    answer = input(
../../../anaconda3/envs/skops/lib/python3.10/site-packages/_pytest/capture.py:192: in read
    raise OSError(
E   OSError: pytest: reading from stdin while output is captured!  Consider using `-s`.

The same does not happen on main. When running with -s, I see the culprit, namely that the clean_skops.py script is being called, which asks for user input and then waits, leading to the pytest error. It is unclear to me why running doctests calls the script.

Another point: The doctests are relatively slow. Is it possible to add an option to exclude them, like with -m "not network"?

@adrinjalali
Copy link
Member Author

I'd ignore the clean_skops.py issue since we should be doing pytest skops, not pytest on the root folder. The other issues I haven't seen and the CI also doesn't complain.

On the speed, I don't notice anything too slow, and I'm quite happy with the speed. But I also don't run tests on save or anything.

I'm happy if you want to add that marker if it's easy to add, in a separate PR.

@BenjaminBossan
Copy link
Collaborator

I'd ignore the clean_skops.py issue since we should be doing pytest skops, not pytest on the root folder.

Yes, it was just surprising to me why the script is being called after enabling doctests. I was just lazy so far and skipped adding skops to pytest because it worked and now it doesn't. WDYT about adding testpaths = ["skops"] to the pytest ini options?

@adrinjalali
Copy link
Member Author

not sure. I feel like that's kinda taking control from the user.

Copy link
Collaborator

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

LGTM

@BenjaminBossan
Copy link
Collaborator

not sure. I feel like that's kinda taking control from the user.

True

@BenjaminBossan BenjaminBossan merged commit 8f1ae0a into skops-dev:main Aug 19, 2022
@adrinjalali adrinjalali deleted the doctest branch August 19, 2022 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable ELLIPSIS and NORMALIZE_WHITESPACE everywhere
2 participants