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

ValueError → AttributeError when partial_fit not implemented in Incremental's model #920

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dask_ml/_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 23 additions & 1 deletion tests/test_incremental.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -235,3 +235,25 @@ 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)
2 changes: 1 addition & 1 deletion tests/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)