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

[MRG] Doctest with print change only adjusts default options for doctest #13991

Merged
merged 36 commits into from
Jun 1, 2019

Conversation

thomasjpfan
Copy link
Member

@thomasjpfan thomasjpfan commented May 30, 2019

Reference Issues/PRs

Fixes #13985
Fixes #13564

What does this implement/fix? Explain your changes.

This PR changes:

  1. Makes NORMALIZE_WHITESPACE and ELLIPSIS the default options.
  2. Changes formatting for estimators by setting print_changed_only=True for doctest.

Any other comments?

This PR only changes print_changed_only on doctests, and not normal tests.

@thomasjpfan thomasjpfan changed the title [MRG] Doctest with print change only [MRG] Doctest with print change only adjusts default options for doctest May 30, 2019
@amueller
Copy link
Member

why did you change two things :-/ I assume the global doctest options are non-controversial while the change only might be.

Also: I really hope you did this automatically ;)

Personally I think this is much more informative. A possible source of confusion could be that locally people get different outputs.

Copy link
Member

@jnothman jnothman left a comment

Choose a reason for hiding this comment

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

There still appear to be some flags used in doctests in this PR:

doc/modules/linear_model.rst:    >>> reg.intercept_ #doctest: +ELLIPSIS
doc/modules/model_evaluation.rst:  >>> hinge_loss(y_true, pred_decision, labels)  #doctest: +ELLIPSIS
setup.cfg:doctest_optionflags = NORMALIZE_WHITESPACE ELLIPSIS
sklearn/datasets/descr/twenty_newsgroups.rst:  >>> vectors.nnz / float(vectors.shape[0])       # doctest: +ELLIPSIS
sklearn/datasets/descr/twenty_newsgroups.rst:  >>> metrics.f1_score(newsgroups_test.target, pred, average='macro')  # doctest: +ELLIPSIS
sklearn/datasets/descr/twenty_newsgroups.rst:  >>> metrics.f1_score(pred, newsgroups_test.target, average='macro')  # doctest: +ELLIPSIS
sklearn/datasets/descr/twenty_newsgroups.rst:  >>> metrics.f1_score(newsgroups_test.target, pred, average='macro')  # doctest: +ELLIPSIS
sklearn/metrics/classification.py:    >>> hinge_loss(y_true, pred_decision, labels)  #doctest: +ELLIPSIS
sklearn/metrics/pairwise.py:    >>> manhattan_distances([[3]], [[3]])#doctest:+ELLIPSIS
sklearn/metrics/pairwise.py:    >>> manhattan_distances([[3]], [[2]])#doctest:+ELLIPSIS
sklearn/metrics/pairwise.py:    >>> manhattan_distances([[2]], [[3]])#doctest:+ELLIPSIS
sklearn/metrics/pairwise.py:         [[1, 2], [0, 3]])#doctest:+ELLIPSIS
sklearn/metrics/pairwise.py:    >>> manhattan_distances(X, y, sum_over_features=False)#doctest:+ELLIPSIS
sklearn/neighbors/unsupervised.py:      >>> neigh.fit(samples)  #doctest: +ELLIPSIS
sklearn/neighbors/unsupervised.py:      ... #doctest: +ELLIPSIS
sklearn/preprocessing/label.py:    >>> le.transform([1, 1, 2, 6]) #doctest: +ELLIPSIS
sklearn/preprocessing/label.py:    >>> le.transform(["tokyo", "tokyo", "paris"]) #doctest: +ELLIPSIS
sklearn/utils/__init__.py:    >>> list(gen_even_slices(10, 10))                     #doctest: +ELLIPSIS
sklearn/utils/__init__.py:    >>> list(gen_even_slices(10, 5))                      #doctest: +ELLIPSIS
setup.cfg:doctest_optionflags = NORMALIZE_WHITESPACE ELLIPSIS
sklearn/linear_model/coordinate_descent.py:    ... #doctest: +NORMALIZE_WHITESPACE
sklearn/linear_model/coordinate_descent.py:    ... #doctest: +NORMALIZE_WHITESPACE
sklearn/linear_model/sag.py:    ... #doctest: +NORMALIZE_WHITESPACE
sklearn/linear_model/sag.py:    ... #doctest: +NORMALIZE_WHITESPACE
sklearn/linear_model/stochastic_gradient.py:    ... #doctest: +NORMALIZE_WHITESPACE
sklearn/linear_model/stochastic_gradient.py:    ... #doctest: +NORMALIZE_WHITESPACE
sklearn/svm/classes.py:    >>> clf.fit(X, y) #doctest: +NORMALIZE_WHITESPACE
sklearn/svm/classes.py:    >>> clf.fit(X, y) #doctest: +NORMALIZE_WHITESPACE
sklearn/svm/classes.py:    >>> clf.fit(X, y) #doctest: +NORMALIZE_WHITESPACE
sklearn/svm/classes.py:    >>> clf.fit(X, y)  #doctest: +NORMALIZE_WHITESPACE



def pytest_runtest_teardown(item, nextitem):
if isinstance(item, DoctestItem):
Copy link
Member

Choose a reason for hiding this comment

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

nice

@jnothman
Copy link
Member

I like this, btw... I think it makes doctest maintenance much more straightforward.

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

Thanks @thomasjpfan , this is very nice!

(Fixed a last few occurrences of +ELLIPSIS)

@rth rth merged commit 2e7e06b into scikit-learn:master Jun 1, 2019
@rth
Copy link
Member

rth commented Jun 1, 2019

Opened a follow-up issue in #14008 about using print_changed_only=True by default for meta-estimators.

@amueller
Copy link
Member

amueller commented Jun 5, 2019

image

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.

should doctests use print_changed_only=True? can put NORMALIZE_WHITESPACE in pytest config
5 participants