Skip to content

feat(operator): reject Count Vectorizer on the Gaussian Naive Bayes operators - #7599

Open
kz930 wants to merge 1 commit into
apache:mainfrom
kz930:fix/7597-gaussiannb-count-vectorizer
Open

feat(operator): reject Count Vectorizer on the Gaussian Naive Bayes operators#7599
kz930 wants to merge 1 commit into
apache:mainfrom
kz930:fix/7597-gaussiannb-count-vectorizer

Conversation

@kz930

@kz930 kz930 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

Gaussian Naive Bayes and Training: Gaussian Naive Bayes offered a Count Vectorizer switch with no working setting. Turning it on ended the execution from inside scikit-learn: CountVectorizer emits a sparse matrix, and GaussianNB validates its input without accept_sparse because it estimates a mean and a variance per feature, which reads the zeros too. The refusal is deliberate on scikit-learn's side, since densifying a text matrix with a large vocabulary is what would exhaust memory.

It is specific to this estimator, not to the switch. The switch is declared once on SklearnModelOpDesc and both families splice it into the pipeline the same way, so every estimator in both groups inherits it whether or not its own can use it.

An estimator that cannot take the sparse matrix now names what to reach for instead, and the shared getOutputSchemas turns that into a compile-time failure naming both. Nothing fires while the switch is off, which is its default, so a freshly dropped operator is not reported invalid before it is configured.

Hiding the switch would have been the closer match to how the family already handles an impossible pairing, since Tfidf Transformer and Text Attribute are hidden when Count Vectorizer is off. It is not available here: a hide keys on a sibling field's value and is evaluated in the frontend, so it cannot be made per estimator on a field the base declares once. It would also leave a workflow already saved with the switch on still failing at run time, which the compile-time check catches.

Any related issues, documentation, discussions?

Fixes #7597.

How was this PR tested?

  • The premise checked against scikit-learn: fitting make_pipeline(CountVectorizer(), Estimator()) on the same documents, GaussianNB raises the TypeError in the issue while MultinomialNB, BernoulliNB and ComplementNB all fit, which is what the message points at.
  • Both operators' specs assert the rejection carries the estimator's own name and the alternatives.
  • The base's spec covers the three states that matter: an estimator naming no alternative still accepts the switch, one naming an alternative rejects it, and neither fires while the switch is off.
  • WorkflowOperator/testOnly *Sklearn*: 62 suites, 421 tests, none failed. scalafmtCheckAll and both scalafix checks clean.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5)

…perators

Gaussian Naive Bayes and Training: Gaussian Naive Bayes offered a Count
Vectorizer switch with no working setting. Turning it on ended the execution
from inside scikit-learn: CountVectorizer emits a sparse matrix, and GaussianNB
validates its input without accept_sparse because it estimates a mean and a
variance per feature, which reads the zeros too. The refusal is deliberate on
scikit-learn's side, since densifying a text matrix with a large vocabulary is
what would exhaust memory.

It is specific to this estimator, not to the switch. Fitting
make_pipeline(CountVectorizer(), Estimator()) on the same documents, only
GaussianNB raises; MultinomialNB, BernoulliNB and ComplementNB accept the sparse
matrix, as do the rest of the estimators both groups use. The switch is declared
once on SklearnModelOpDesc and both families splice it in the same way, so all of
them inherit it whether or not their estimator can use it.

An estimator that cannot take the sparse matrix now names what to reach for
instead, and the shared getOutputSchemas turns that into a compile-time failure
naming both. Hiding the switch would have been the closer match to how the
family handles an impossible pairing already, but a hide keys on a sibling
field's value and is evaluated in the frontend, so it cannot be made per
estimator on a field the base declares once. It would also leave a workflow
already saved with the switch on still failing at run time.

The message names the estimator and the three Naive Bayes variants that do
accept the matrix. Nothing fires while the switch is off, which is its default,
so a freshly dropped operator is not reported invalid before it is configured.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @Yicong-Huang, @Ma77Ball, @aglinxinyuan
    You can notify them by mentioning @Yicong-Huang, @Ma77Ball, @aglinxinyuan in a comment.

@kz930

kz930 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

@Ma77Ball @carloea2 May you take a look at this?

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.63%. Comparing base (7daf8d7) to head (d44633f).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #7599   +/-   ##
=========================================
  Coverage     88.63%   88.63%           
  Complexity     4346     4346           
=========================================
  Files          1177     1177           
  Lines         46896    46896           
  Branches       5230     5230           
=========================================
  Hits          41568    41568           
  Misses         3568     3568           
  Partials       1760     1760           
Flag Coverage Δ *Carryforward flag
access-control-service 70.00% <ø> (ø) Carriedforward from 7daf8d7
agent-service 98.62% <ø> (ø) Carriedforward from 7daf8d7
amber 84.71% <ø> (ø) Carriedforward from 7daf8d7
computing-unit-managing-service 60.38% <ø> (ø)
config-service 77.31% <ø> (ø)
file-service 69.05% <ø> (ø) Carriedforward from 7daf8d7
frontend 89.98% <ø> (ø) Carriedforward from 7daf8d7
notebook-migration-service 78.89% <ø> (ø)
pyamber 97.52% <ø> (ø) Carriedforward from 7daf8d7
workflow-compiling-service 57.89% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

Gaussian Naive Bayes offers a Count Vectorizer switch that always ends the run

2 participants