Skip to content

Commit 5592a2e

Browse files
rlamyjnothman
authored andcommitted
[MRG] PyPy support for all but a couple of estimators (scikit-learn#11010)
1 parent 813d7de commit 5592a2e

File tree

24 files changed

+186
-34
lines changed

24 files changed

+186
-34
lines changed

.circleci/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ jobs:
6565
path: ~/log.txt
6666
destination: log.txt
6767

68+
pypy3:
69+
docker:
70+
- image: pypy:3-6.0.0
71+
steps:
72+
- restore_cache:
73+
keys:
74+
- pypy3-ccache-{{ .Branch }}
75+
- pypy3-ccache
76+
- checkout
77+
- run: ./build_tools/circle/build_test_pypy.sh
78+
- save_cache:
79+
key: pypy3-ccache-{{ .Branch }}-{{ .BuildNum }}
80+
paths:
81+
- ~/.ccache
82+
- ~/.cache/pip
83+
6884
deploy:
6985
docker:
7086
- image: circleci/python:3.6.1
@@ -88,6 +104,7 @@ workflows:
88104
jobs:
89105
- python3
90106
- python2
107+
- pypy3
91108
- deploy:
92109
requires:
93110
- python3
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
set -e
4+
5+
apt-get -yq update
6+
apt-get -yq install libatlas-dev libatlas-base-dev liblapack-dev gfortran ccache
7+
8+
pip install virtualenv
9+
10+
if command -v pypy3; then
11+
virtualenv -p $(command -v pypy3) pypy-env
12+
elif command -v pypy; then
13+
virtualenv -p $(command -v pypy) pypy-env
14+
fi
15+
16+
source pypy-env/bin/activate
17+
18+
python --version
19+
which python
20+
21+
pip install --extra-index https://antocuni.github.io/pypy-wheels/ubuntu numpy==1.14.4 Cython pytest
22+
pip install "scipy>=1.1.0" sphinx numpydoc docutils
23+
24+
ccache -M 512M
25+
export CCACHE_COMPRESS=1
26+
export PATH=/usr/lib/ccache:$PATH
27+
28+
pip install -e .
29+
30+
make test

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@
55
# doc/modules/clustering.rst and use sklearn from the local folder rather than
66
# the one from site-packages.
77

8+
import platform
89
from distutils.version import LooseVersion
910

1011
import pytest
1112
from _pytest.doctest import DoctestItem
1213

1314

1415
def pytest_collection_modifyitems(config, items):
16+
17+
# FeatureHasher is not compatible with PyPy
18+
if platform.python_implementation() == 'PyPy':
19+
skip_marker = pytest.mark.skip(
20+
reason='FeatureHasher is not compatible with PyPy')
21+
for item in items:
22+
if item.name == 'sklearn.feature_extraction.hashing.FeatureHasher':
23+
item.add_marker(skip_marker)
24+
1525
# numpy changed the str/repr formatting of numpy arrays in 1.14. We want to
1626
# run doctests only for numpy >= 1.14.
1727
skip_doctests = True

doc/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import os
12
from os.path import exists
23
from os.path import join
34
import warnings
45

56
import numpy as np
67

8+
from sklearn.utils import IS_PYPY
79
from sklearn.utils.testing import SkipTest
810
from sklearn.utils.testing import check_skip_network
911
from sklearn.datasets import get_data_home
@@ -56,6 +58,8 @@ def setup_twenty_newsgroups():
5658

5759

5860
def setup_working_with_text_data():
61+
if IS_PYPY and os.environ.get('CI', None):
62+
raise SkipTest('Skipping too slow test with PyPy on CI')
5963
check_skip_network()
6064
cache_path = _pkl_filepath(get_data_home(), CACHE_NAME)
6165
if not exists(cache_path):
@@ -98,6 +102,8 @@ def pytest_runtest_setup(item):
98102
setup_working_with_text_data()
99103
elif fname.endswith('modules/compose.rst') or is_index:
100104
setup_compose()
105+
elif IS_PYPY and fname.endswith('modules/feature_extraction.rst'):
106+
raise SkipTest('FeatureHasher is not compatible with PyPy')
101107
elif fname.endswith('modules/impute.rst'):
102108
setup_impute()
103109
elif fname.endswith('statistical_inference/unsupervised_learning.rst'):

doc/developers/advanced_installation.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ Scikit-learn requires:
3838
- NumPy (>= 1.8.2),
3939
- SciPy (>= 0.13.3).
4040

41+
.. note::
42+
43+
For installing on PyPy, PyPy3-v5.10+, Numpy 1.14.0+, and scipy 1.1.0+
44+
are required. For PyPy, only installation instructions with pip apply.
45+
46+
4147
Building Scikit-learn also requires
4248

4349
- Cython >=0.23

doc/developers/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ and Cython optimizations.
352352

353353
* Travis is used for testing on Linux platforms
354354
* Appveyor is used for testing on Windows platforms
355-
* CircleCI is used to build the docs for viewing
355+
* CircleCI is used to build the docs for viewing and for testing with PyPy on Linux
356356

357357
Please note that if one of the following markers appear in the latest commit
358358
message, the following actions are taken.

doc/faq.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,10 @@ careful choice of algorithms.
179179
Do you support PyPy?
180180
--------------------
181181

182-
In case you didn't know, `PyPy <http://pypy.org/>`_ is the new, fast,
183-
just-in-time compiling Python implementation. We don't support it.
184-
When the `NumPy support <http://buildbot.pypy.org/numpy-status/latest.html>`_
185-
in PyPy is complete or near-complete, and SciPy is ported over as well,
186-
we can start thinking of a port.
187-
We use too much of NumPy to work with a partial implementation.
182+
In case you didn't know, `PyPy <http://pypy.org/>`_ is an alternative
183+
Python implementation with a built-in just-in-time compiler. Experimental
184+
support for PyPy3-v5.10+ has been added, which requires Numpy 1.14.0+,
185+
and scipy 1.1.0+.
188186

189187
How do I deal with string data (or trees, graphs...)?
190188
-----------------------------------------------------

doc/install.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ it as ``scikit-learn[alldeps]``. The most common use case for this is in a
5252
application or a Docker image. This option is not intended for manual
5353
installation from the command line.
5454

55+
.. note::
56+
57+
For installing on PyPy, PyPy3-v5.10+, Numpy 1.14.0+, and scipy 1.1.0+
58+
are required.
59+
60+
5561
For installation instructions for more distributions see
5662
:ref:`other distributions <install_by_distribution>`.
5763
For compiling the development version from source, or building the package

doc/whats_new/v0.20.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ Miscellaneous
431431
:issue:`9101` by :user:`alex-33 <alex-33>`
432432
and :user:`Maskani Filali Mohamed <maskani-moh>`.
433433

434+
- Add almost complete PyPy 3 support. Known unsupported functionalities are
435+
:func:`datasets.load_svmlight_file`, :class:`feature_extraction.FeatureHasher` and
436+
:class:`feature_extraction.text.HashingVectorizer`. For running on PyPy, PyPy3-v5.10+,
437+
Numpy 1.14.0+, and scipy 1.1.0+ are required.
438+
:issue:`11010` by :user:`Ronan Lamy <rlamy>` and `Roman Yurchak`_.
439+
434440
Bug fixes
435441
.........
436442

setup.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Copyright (C) 2007-2009 Cournapeau David <cournape@gmail.com>
44
# 2010 Fabian Pedregosa <fabian.pedregosa@inria.fr>
55
# License: 3-clause BSD
6-
descr = """A set of python modules for machine learning and data mining"""
76

87
import sys
98
import os
9+
import platform
1010
import shutil
1111
from distutils.command.clean import clean as Clean
1212
from pkg_resources import parse_version
@@ -41,8 +41,12 @@
4141

4242
VERSION = sklearn.__version__
4343

44-
SCIPY_MIN_VERSION = '0.13.3'
45-
NUMPY_MIN_VERSION = '1.8.2'
44+
if platform.python_implementation() == 'PyPy':
45+
SCIPY_MIN_VERSION = '1.1.0'
46+
NUMPY_MIN_VERSION = '1.14.0'
47+
else:
48+
SCIPY_MIN_VERSION = '0.13.3'
49+
NUMPY_MIN_VERSION = '1.8.2'
4650

4751

4852
# Optional setuptools features
@@ -185,6 +189,10 @@ def setup_package():
185189
'Programming Language :: Python :: 3.4',
186190
'Programming Language :: Python :: 3.5',
187191
'Programming Language :: Python :: 3.6',
192+
('Programming Language :: Python :: '
193+
'Implementation :: CPython'),
194+
('Programming Language :: Python :: '
195+
'Implementation :: PyPy')
188196
],
189197
cmdclass=cmdclass,
190198
install_requires=[

0 commit comments

Comments
 (0)