Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX Fix string formatting in the error message in CategoricalNB #16090

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

Merged
merged 5 commits into from
Jan 12, 2020

Conversation

madhuracj
Copy link
Contributor

Reference Issues/PRs

What does this implement/fix? Explain your changes.

This is a simple fix, correcting the string formatting in the error message.

Any other comments?

@madhuracj madhuracj changed the title Fix string formatting in the error message [MRG] Fix string formatting in the error message Jan 10, 2020
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @madhuracj !

This needs a test in sklearn/tests/test_naive_bayes.py at test_categoricalnb. Something like this:

--- a/sklearn/tests/test_naive_bayes.py
+++ b/sklearn/tests/test_naive_bayes.py
@@ -667,6 +667,12 @@ def test_categoricalnb():
     assert_raise_message(ValueError, error_msg, clf.predict, X)
     assert_raise_message(ValueError, error_msg, clf.fit, X, y)
 
+    # Check error is failed for incorrect X
+    X = np.array([[1, 4, 1], [2, 5, 6]])
+    msg = "Expected input with 2 features, got 3 instead"
+    with pytest.raises(ValueError, match=msg):
+        clf.predict(X)
+
     # Test alpha
     X3_test = np.array([[2, 5]])
     # alpha=1 increases the count of all categories by one so the final

@madhuracj
Copy link
Contributor Author

Thanks @thomasjpfan, I've updated the PR.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasjpfan thomasjpfan changed the title [MRG] Fix string formatting in the error message [MRG] BUG Fix string formatting in the error message Jan 10, 2020
@thomasjpfan
Copy link
Member

thomasjpfan commented Jan 10, 2020

Please add an entry to the change log at doc/whats_new/v0.23.rst with a FIX tag. Like the other entries there, please reference this pull request with :pr: and credit yourself (and other contributors if applicable) with :user:.

@thomasjpfan thomasjpfan changed the title [MRG] BUG Fix string formatting in the error message [MRG] FIX Fix string formatting in the error message Jan 10, 2020
Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @madhuracj.

Not sure this needs a what's new entry @thomasjpfan? this isn't a bugfix

@thomasjpfan
Copy link
Member

It may not be a numerical bug. I can see this as a user interface bug of "not showing the correct error message".

I am okay with not having a whats new for this.

@madhuracj
Copy link
Contributor Author

@thomasjpfan Changelog entry added in ba48799 in case you want to include one.

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whats new is in alphabetic order by the module name. In this case sklearn.naive_bayes is after the sklearn.model_selection section.

@thomasjpfan thomasjpfan merged commit 073de7c into scikit-learn:master Jan 12, 2020
@thomasjpfan thomasjpfan changed the title [MRG] FIX Fix string formatting in the error message FIX Fix string formatting in the error message in CategoricalNB Jan 12, 2020
thomasjpfan pushed a commit to thomasjpfan/scikit-learn that referenced this pull request Feb 22, 2020
panpiort8 pushed a commit to panpiort8/scikit-learn that referenced this pull request Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants