8000 Merged changes from #14545 and further improvements · arpanchowdhry/scikit-learn@47d24af · GitHub
[go: up one dir, main page]

Skip to content

Commit 47d24af

Browse files
committed
Merged changes from scikit-learn#14545 and further improvements
2 parents d9fa05a + 864d32a commit 47d24af

File tree

109 files changed

+1564
-606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1564
-606
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ jobs:
4949
- MKL_NUM_THREADS: 2
5050
- MINICONDA_PATH: ~/miniconda
5151
- CONDA_ENV_NAME: testenv
52-
- PYTHON_VERSION: 3
52+
# TODO: Revert to 3 when wheel issue with conda installation of python 3.7.4
53+
- PYTHON_VERSION: 3.7.3
5354
steps:
5455
- checkout
5556
- run: ./build_tools/circle/checkout_merge_commit.sh

benchmarks/bench_plot_nmf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,13 @@ def fit(self, X, y=None, **params):
213213
return self
214214

215215
def transform(self, X):
216-
check_is_fitted(self, 'components_')
216+
check_is_fitted(self)
217217
H = self.components_
218218
W, _, self.n_iter_ = self._fit_transform(X, H=H, update_H=False)
219219
return W
220220

221221
def inverse_transform(self, W):
222-
check_is_fitted(self, 'components_')
222+
check_is_fitted(self)
223223
return np.dot(W, self.components_)
224224

225225
def fit_transform(self, X, y=None, W=None, H=None):

build_tools/azure/install.sh

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,26 @@ make_conda() {
2424
source activate $VIRTUALENV
2525
}
2626

27+
version_ge() {
28+
# The two version numbers are seperated with a new line is piped to sort
29+
# -rV. The -V activates for version number sorting and -r sorts in
30+
# decending order. If the first argument is the top element of the sort, it
31+
# is greater than or equal to the second argument.
32+
test "$(printf "${1}\n${2}" | sort -rV | head -n 1)" == "$1"
33+
}
34+
2735
if [[ "$DISTRIB" == "conda" ]]; then
28-
TO_INSTALL="python=$PYTHON_VERSION pip pytest=$PYTEST_VERSION pytest-cov \
29-
numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION \
36+
37+
# TODO
38+
# Remove when wheel issue is fixed with conda installations of python 3.7.4
39+
if [[ "$PYTHON_VERSION" == "*" ]]; then
40+
PINNED_PYTHON_VERSION="3.7.3"
41+
else
42+
PINNED_PYTHON_VERSION=$PYTHON_VERSION
43+
fi
44+
45+
TO_INSTALL="python=$PINNED_PYTHON_VERSION pip pytest=$PYTEST_VERSION \
46+
pytest-cov numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION \
3047
cython=$CYTHON_VERSION joblib=$JOBLIB_VERSION"
3148

3249
if [[ "$INSTALL_MKL" == "true" ]]; then
@@ -51,6 +68,15 @@ if [[ "$DISTRIB" == "conda" ]]; then
5168
TO_INSTALL="$TO_INSTALL matplotlib=$MATPLOTLIB_VERSION"
5269
fi
5370

71+
# Old packages coming from the 'free' conda channel have been removed but
72+
# we are using them for testing Python 3.5. See
73+
# https://www.anaconda.com/why-we-removed-the-free-channel-in-conda-4-7/
74+
# for more details. restore_free_channel is defined starting from conda 4.7
75+
conda_version=$(conda -V | awk '{print $2}')
76+
if version_ge "$conda_version" "4.7.0" && [[ "$PYTHON_VERSION" == "3.5" ]]; then
77+
conda config --set restore_free_channel true
78+
fi
79+
5480
make_conda $TO_INSTALL
5581
if [[ "$PYTHON_VERSION" == "*" ]]; then
5682
pip install pytest-xdist

build_tools/azure/test_pytest_soft_dependency.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ source activate $VIRTUALENV
77
conda remove -y py pytest || pip uninstall -y py pytest
88

99
if [[ "$COVERAGE" == "true" ]]; then
10+
# conda may remove coverage when uninstall pytest and py
11+
pip install coverage
1012
# Need to append the coverage to the existing .coverage generated by
1113
# running the tests. Make sure to reuse the same coverage
1214
# configuration as the one used by the main pytest run to be

build_tools/circle/build_doc.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ fi
151151
# The pipefail is requested to propagate exit code
152152
set -o pipefail && cd doc && make $make_args 2>&1 | tee ~/log.txt
153153

154+
# Insert the version warning for deployment
155+
find _build/html/stable -name "*.html" | xargs sed -i '/<\/body>/ i \
156+
\ <script src="https://scikit-learn.org/versionwarning.js"></script>'
157+
154158
cd -
155159
set +o pipefail
156160

doc/developers/contributing.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,60 @@ If you often need to look at the documentation generated by CircleCI, e.g. when
659659
reviewing pull requests, you may find :ref:`this tip
660660
<viewing_rendered_html_documentation>` very handy.
661661

662+
.. _testing_coverage:
663+
664+
Testing and improving test coverage
665+
===================================
666+
667+
High-quality `unit testing <https://en.wikipedia.org/wiki/Unit_testing>`_
668+
is a corner-stone of the scikit-learn development process. For this
669+
purpose, we use the `pytest <https://docs.pytest.org>`_
670+
package. The tests are functions appropriately named, located in `tests`
671+
subdirectories, that check the validity of the algorithms and the
672+
different options of the code.
673+
674+
The full scikit-learn tests can be run using 'make' in the root folder.
675+
Alternatively, running 'pytest' in a folder will run all the tests of
676+
the corresponding subpackages.
677+
678+
We expect code coverage of new features to be at least around 90%.
679+
680+
For guidelines on how to use ``pytest`` efficiently, see the
681+
:ref:`pytest_tips`.
682+
683+
Writing matplotlib related tests
684+
--------------------------------
685+
686+
Test fixtures ensure that a set of tests will be executing with the appropriate
687+
initialization and cleanup. The scikit-learn test suite implements a fixture
688+
which can be used with ``matplotlib``.
689+
690+
``pyplot``
691+
The ``pyplot`` fixture should be used when a test function is dealing with
692+
``matplotlib``. ``matplotlib`` is a soft dependency and is not required.
693+
This fixture is in charge of skipping the tests if ``matplotlib`` is not
694+
installed. In addition, figures created during the tests will be
695+
automatically closed once the test function has been executed.
696+
697+
To use this fixture in a test function, one needs to pass it as an
698+
argument::
699+
700+
def test_requiring_mpl_fixture(pyplot):
701+
# you can now safely use matplotlib
702+
703+
Workflow to improve test coverage
704+
---------------------------------
705+
706+
To test code coverage, you need to install the `coverage
707+
<https://pypi.org/project/coverage/>`_ package in addition to pytest.
708+
709+
1. Run 'make test-coverage'. The output lists for each file the line
710+
numbers that are not tested.
711+
712+
2. Find a low hanging fruit, looking at which lines are not tested,
713+
write or adapt a test specifically for these lines.
714+
715+
3. Loop.
662716

663717
Issue Tracker Tags
664718
==================

0 commit comments

Comments
 (0)
0