diff --git a/Makefile b/Makefile index 428ca5de5f6ae62d0fdc540e85bdf100c439e54b..91260bb681c71f33fb077b44e0c472122eeffe3b 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,14 @@ CYTHON ?= cython NOSETESTS ?= nosetests CTAGS ?= ctags +# skip doctests on 32bit python +BITS := $(shell python -c 'import struct; print(8 * struct.calcsize("P"))') + +ifeq ($(BITS),32) + NOSETESTS:=$(NOSETESTS) -c setup32.cfg +endif + + all: clean inplace test clean-ctags: @@ -28,9 +36,11 @@ test-code: in test-sphinxext: $(NOSETESTS) -s -v doc/sphinxext/ test-doc: +ifeq ($(BITS),64) $(NOSETESTS) -s -v doc/*.rst doc/modules/ doc/datasets/ \ doc/developers doc/tutorial/basic doc/tutorial/statistical_inference \ doc/tutorial/text_analytics +endif test-coverage: rm -rf coverage .coverage diff --git a/setup32.cfg b/setup32.cfg new file mode 100644 index 0000000000000000000000000000000000000000..7294cb813fc8dc835f19c6d920e9b07354a67db3 --- /dev/null +++ b/setup32.cfg @@ -0,0 +1,22 @@ +# This config file is here to skip doctests on 32bit linux when running make or make test +# For newer versions of nose, we can simply use "NOSE_IGNORE_CONFIG_FILES", which +# we should do in the future. + +[aliases] +# python2.7 has upgraded unittest and it is no longer compatible with some +# of our tests, so we run all through nose +test = nosetests + +[nosetests] +# nosetests skips test files with the executable bit by default +# which can silently hide failing tests. +# There are no executable scripts within the scikit-learn project +# so let's turn the --exe flag on to avoid skipping tests by +# mistake. +exe = 1 +cover-html = 1 +cover-html-dir = coverage +cover-package = sklearn + +detailed-errors = 1 +with-doctest = 0 diff --git a/sklearn/ensemble/tests/test_forest.py b/sklearn/ensemble/tests/test_forest.py index 631c726f0381e077ac6f04942ca27f645617b31a..eb6568b72be86cced84998f154d0016a6fa97978 100644 --- a/sklearn/ensemble/tests/test_forest.py +++ b/sklearn/ensemble/tests/test_forest.py @@ -30,6 +30,7 @@ from sklearn.utils.testing import assert_greater_equal from sklearn.utils.testing import assert_raises from sklearn.utils.testing import assert_warns from sklearn.utils.testing import ignore_warnings +from sklearn.utils.testing import skip_if_32bit from sklearn import datasets from sklearn.decomposition import TruncatedSVD @@ -229,6 +230,7 @@ def check_importances(X, y, name, criterion): assert_less(np.abs(importances - importances_bis).mean(), 0.001) +@skip_if_32bit def test_importances(): X, y = datasets.make_classification(n_samples=500, n_features=10, n_informative=3, n_redundant=0, diff --git a/sklearn/ensemble/tests/test_gradient_boosting.py b/sklearn/ensemble/tests/test_gradient_boosting.py index 4f2329be5035818d754ebf33f3f0f17b45b87ba2..766505262bd762ef730b3a9fa7ca21bf67ddf33a 100644 --- a/sklearn/ensemble/tests/test_gradient_boosting.py +++ b/sklearn/ensemble/tests/test_gradient_boosting.py @@ -26,7 +26,7 @@ from sklearn.utils.testing import assert_less from sklearn.utils.testing import assert_raises from sklearn.utils.testing import assert_true from sklearn.utils.testing import assert_warns -from sklearn.utils.testing import ignore_warnings +from sklearn.utils.testing import skip_if_32bit from sklearn.utils.validation import DataConversionWarning from sklearn.utils.validation import NotFittedError @@ -186,9 +186,9 @@ def check_boston(presort, loss, subsample): ones = np.ones(len(boston.target)) last_y_pred = None for sample_weight in None, ones, 2*ones: - clf = GradientBoostingRegressor(n_estimators=100, + clf = GradientBoostingRegressor(n_estimators=100, loss=loss, - max_depth=4, + max_depth=4, subsample=subsample, min_samples_split=1, random_state=1, @@ -199,10 +199,10 @@ def check_boston(presort, loss, subsample): sample_weight=sample_weight) leaves = clf.apply(boston.data) assert_equal(leaves.shape, (506, 100)) - + y_pred = clf.predict(boston.data) mse = mean_squared_error(boston.target, y_pred) - assert_less( mse, 6.0 ) + assert_less(mse, 6.0) if last_y_pred is not None: assert_array_almost_equal(last_y_pred, y_pred) @@ -211,17 +211,17 @@ def check_boston(presort, loss, subsample): def test_boston(): - for presort, loss, subsample in product(('auto', True, False), - ('ls', 'lad', 'huber'), + for presort, loss, subsample in product(('auto', True, False), + ('ls', 'lad', 'huber'), (1.0, 0.5)): yield check_boston, presort, loss, subsample def check_iris(presort, subsample, sample_weight): # Check consistency on dataset iris. - clf = GradientBoostingClassifier(n_estimators=100, + clf = GradientBoostingClassifier(n_estimators=100, loss='deviance', - random_state=1, + random_state=1, subsample=subsample, presort=presort) clf.fit(iris.data, iris.target, sample_weight=sample_weight) @@ -234,8 +234,8 @@ def check_iris(presort, subsample, sample_weight): def test_iris(): ones = np.ones(len(iris.target)) - for presort, subsample, sample_weight in product(('auto', True, False), - (1.0, 0.5), + for presort, subsample, sample_weight in product(('auto', True, False), + (1.0, 0.5), (None, ones)): yield check_iris, presort, subsample, sample_weight @@ -250,7 +250,7 @@ def test_regression_synthetic(): # Friedman1 X, y = datasets.make_friedman1(n_samples=1200, - random_state=random_state, + random_state=random_state, noise=1.0) X_train, y_train = X[:200], y[:200] X_test, y_test = X[200:], y[200:] @@ -1028,21 +1028,22 @@ def test_non_uniform_weights_toy_edge_case_clf(): gb.fit(X, y, sample_weight=sample_weight) assert_array_equal(gb.predict([[1, 0]]), [1]) + def check_sparse_input(EstimatorClass, X, X_sparse, y): dense = EstimatorClass(n_estimators=10, random_state=0, max_depth=2).fit(X, y) - sparse = EstimatorClass(n_estimators=10, random_state=0, max_depth=2, - presort=False).fit(X_sparse, y) - auto = EstimatorClass(n_estimators=10, random_state=0, max_depth=2, - presort='auto').fit(X_sparse, y) + sparse = EstimatorClass(n_estimators=10, random_state=0, max_depth=2, + presort=False).fit(X_sparse, y) + auto = EstimatorClass(n_estimators=10, random_state=0, max_depth=2, + presort='auto').fit(X_sparse, y) assert_array_almost_equal(sparse.apply(X), dense.apply(X)) assert_array_almost_equal(sparse.predict(X), dense.predict(X)) - assert_array_almost_equal(sparse.feature_importances_, + assert_array_almost_equal(sparse.feature_importances_, dense.feature_importances_) assert_array_almost_equal(sparse.apply(X), auto.apply(X)) assert_array_almost_equal(sparse.predict(X), auto.predict(X)) - assert_array_almost_equal(sparse.feature_importances_, + assert_array_almost_equal(sparse.feature_importances_, auto.feature_importances_) if isinstance(EstimatorClass, GradientBoostingClassifier): @@ -1057,6 +1058,7 @@ def check_sparse_input(EstimatorClass, X, X_sparse, y): auto.predict_log_proba(X)) +@skip_if_32bit def test_sparse_input(): ests = (GradientBoostingClassifier, GradientBoostingRegressor) sparse_matrices = (csr_matrix, csc_matrix, coo_matrix) diff --git a/sklearn/feature_selection/tests/test_from_model.py b/sklearn/feature_selection/tests/test_from_model.py index f28426d515196613a093a08aad351dfca4f0a002..06dc3d7f425c2815c9de1da207f843a0c49c5eb8 100644 --- a/sklearn/feature_selection/tests/test_from_model.py +++ b/sklearn/feature_selection/tests/test_from_model.py @@ -5,11 +5,11 @@ from nose.tools import assert_raises, assert_true from sklearn.utils.testing import assert_less from sklearn.utils.testing import assert_greater -from sklearn.utils.testing import assert_equal from sklearn.utils.testing import assert_array_almost_equal from sklearn.utils.testing import assert_array_equal from sklearn.utils.testing import assert_almost_equal from sklearn.utils.testing import assert_warns +from sklearn.utils.testing import skip_if_32bit from sklearn import datasets from sklearn.linear_model import LogisticRegression, SGDClassifier, Lasso @@ -22,6 +22,7 @@ iris = datasets.load_iris() data, y = iris.data, iris.target rng = np.random.RandomState(0) + def test_transform_linear_model(): for clf in (LogisticRegression(C=0.1), LinearSVC(C=0.01, dual=False), @@ -62,6 +63,7 @@ def test_input_estimator_unchanged(): assert_true(transformer.estimator is est) +@skip_if_32bit def test_feature_importances(): X, y = datasets.make_classification( n_samples=1000, n_features=10, n_informative=3, n_redundant=0, @@ -88,7 +90,7 @@ def test_feature_importances(): transformer = SelectFromModel(estimator=est) transformer.fit(X, y, sample_weight=sample_weight) importances = transformer.estimator_.feature_importances_ - transformer.fit(X, y, sample_weight=3*sample_weight) + transformer.fit(X, y, sample_weight=3 * sample_weight) importances_bis = transformer.estimator_.feature_importances_ assert_almost_equal(importances, importances_bis) diff --git a/sklearn/preprocessing/tests/test_data.py b/sklearn/preprocessing/tests/test_data.py index 7a91d46aeacd4451c113c505f2e8bbf2481d08bb..9c107469091ce5931063d9a8dcd337f695025878 100644 --- a/sklearn/preprocessing/tests/test_data.py +++ b/sklearn/preprocessing/tests/test_data.py @@ -29,6 +29,7 @@ from sklearn.utils.testing import assert_warns_message from sklearn.utils.testing import assert_no_warnings from sklearn.utils.testing import ignore_warnings from sklearn.utils.testing import assert_allclose +from sklearn.utils.testing import skip_if_32bit from sklearn.utils.sparsefuncs import mean_variance_axis from sklearn.preprocessing.data import _transform_selected @@ -171,6 +172,7 @@ def test_scale_1d(): assert_array_equal(scale(X, with_mean=False, with_std=False), X) +@skip_if_32bit def test_standard_scaler_numerical_stability(): """Test numerical stability of scaling""" # np.log(1e-5) is taken because of its floating point representation diff --git a/sklearn/utils/testing.py b/sklearn/utils/testing.py index 9dcee223f11cd3ef1e1b36ccbbd6242ee8bee91d..0414f246369599855682670b00edd324badff29b 100644 --- a/sklearn/utils/testing.py +++ b/sklearn/utils/testing.py @@ -16,6 +16,7 @@ import warnings import sys import re import platform +import struct import scipy as sp import scipy.io @@ -683,6 +684,18 @@ def if_matplotlib(func): return run_test +def skip_if_32bit(func): + """Test decorator that skips tests on 32bit platforms.""" + @wraps(func) + def run_test(*args, **kwargs): + bits = 8 * struct.calcsize("P") + if bits == 32: + raise SkipTest('Test skipped on 32bit platforms.') + else: + return func(*args, **kwargs) + return run_test + + def if_not_mac_os(versions=('10.7', '10.8', '10.9'), message='Multi-process bug in Mac OS X >= 10.7 ' '(see issue #636)'): diff --git a/sklearn/utils/tests/test_extmath.py b/sklearn/utils/tests/test_extmath.py index 107f5b845e1d9eb5152fb62e29e4c2fe248b2214..0df11daed48e3d0e5b764444508380c881b30988 100644 --- a/sklearn/utils/tests/test_extmath.py +++ b/sklearn/utils/tests/test_extmath.py @@ -16,6 +16,7 @@ from sklearn.utils.testing import assert_array_almost_equal from sklearn.utils.testing import assert_true from sklearn.utils.testing import assert_greater from sklearn.utils.testing import assert_raises +from sklearn.utils.testing import skip_if_32bit from sklearn.utils.extmath import density from sklearn.utils.extmath import logsumexp @@ -424,6 +425,7 @@ def test_incremental_variance_update_formulas(): assert_almost_equal(final_count, A.shape[0]) +@skip_if_32bit def test_incremental_variance_numerical_stability(): # Test Youngs and Cramer incremental variance formulas.