From 859f20463d24fbf8d7a2e8e327bbdad698487531 Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 16 Apr 2022 19:48:41 -0400 Subject: [PATCH 1/2] =?UTF-8?q?TST:=20ValueError=20=E2=86=92=20AttributeEr?= =?UTF-8?q?ror?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dask_ml/_partial.py | 2 +- tests/test_incremental.py | 23 ++++++++++++++++++++++- tests/test_partial.py | 2 +- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/dask_ml/_partial.py b/dask_ml/_partial.py index 943237336..3f9fb2cf9 100644 --- a/dask_ml/_partial.py +++ b/dask_ml/_partial.py @@ -95,7 +95,7 @@ def fit( if not hasattr(model, "partial_fit"): msg = "The class '{}' does not implement 'partial_fit'." - raise ValueError(msg.format(type(model))) + raise AttributeError(msg.format(type(model))) order = list(range(nblocks)) if shuffle_blocks: diff --git a/tests/test_incremental.py b/tests/test_incremental.py index 7867a3b51..a6a97279e 100644 --- a/tests/test_incremental.py +++ b/tests/test_incremental.py @@ -9,7 +9,7 @@ from dask.array.utils import assert_eq from scipy.sparse import csr_matrix from sklearn.base import clone -from sklearn.linear_model import SGDClassifier, SGDRegressor +from sklearn.linear_model import SGDClassifier, SGDRegressor, LinearRegression from sklearn.pipeline import make_pipeline import dask_ml.feature_extraction.text @@ -235,3 +235,24 @@ def test_incremental_sparse_inputs(): clf_output = clf.predict(X).astype(np.int64) assert_eq(clf_output, wrap_output, ignore_dtype=True) + +def test_no_partial_fit(): + # Create data + n, d = 100, 10 + X_np = np.random.uniform(size=(n, d)) + y_np = np.random.uniform(size=n) + X_da = da.from_array(X_np, chunks=(n//2, -1)) + y_da = da.from_array(y_np, chunks=n//2) + + est = LinearRegression() + dask_est = Incremental(est) + + with pytest.raises(AttributeError, match="partial_fit"): + dask_est.fit(X_np, y_np) + with pytest.raises(AttributeError, match="partial_fit"): + dask_est.partial_fit(X_np, y_np) + + with pytest.raises(AttributeError, match="partial_fit"): + dask_est.fit(X_da, y_da) + with pytest.raises(AttributeError, match="partial_fit"): + dask_est.partial_fit(X_da, y_da) diff --git a/tests/test_partial.py b/tests/test_partial.py index 03e52ec84..4507ac28a 100644 --- a/tests/test_partial.py +++ b/tests/test_partial.py @@ -114,5 +114,5 @@ def test_bag(): def test_no_partial_fit_raises(): X, y = make_classification(chunks=50) - with pytest.raises(ValueError, match="RandomForestClassifier"): + with pytest.raises(AttributeError, match="does not implement 'partial_fit'"): fit(RandomForestClassifier(), X, y) From 49793510633dddbe9e4bf2d02b5f43df2952e4fc Mon Sep 17 00:00:00 2001 From: Scott Date: Sat, 16 Apr 2022 21:09:20 -0400 Subject: [PATCH 2/2] black --- tests/test_incremental.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_incremental.py b/tests/test_incremental.py index a6a97279e..2e67484d6 100644 --- a/tests/test_incremental.py +++ b/tests/test_incremental.py @@ -236,13 +236,14 @@ def test_incremental_sparse_inputs(): assert_eq(clf_output, wrap_output, ignore_dtype=True) + def test_no_partial_fit(): # Create data n, d = 100, 10 X_np = np.random.uniform(size=(n, d)) y_np = np.random.uniform(size=n) - X_da = da.from_array(X_np, chunks=(n//2, -1)) - y_da = da.from_array(y_np, chunks=n//2) + X_da = da.from_array(X_np, chunks=(n // 2, -1)) + y_da = da.from_array(y_np, chunks=n // 2) est = LinearRegression() dask_est = Incremental(est)