Repository navigation
FIX: HTML representation with nested meta-estimator - #33889
Conversation
It is weird because for the |
| estimator.get_feature_names_out(), is_fitted_css_class | ||
| ) | ||
| try: | ||
| output_features = estimator.get_feature_names_out() |
There was a problem hiding this comment.
If it is to test the availability of get_feature_names_out, then if hasattr(estimator, get_feature_names_out) would be better than catching whatever exception I think.
There was a problem hiding this comment.
I had tried that I think and there were cases when it wasn't working. It happened on this PR: #33779
There was a problem hiding this comment.
Would it be possible to be more specific instead of generic Exception? I think you just need to catch NotFittedError and AttributeError.
On main, it breakes. |
|
Yes but we get "0 features" (at the output of the ColumnTransformer) while the fitted |
I missed that!.. It maybe another issue - with the ColumnTransformer. I'll keep searching.. |
|
On your example #33887, Besides that, I need to check the column names entering |
|
Hi @DeaMariaLeon, thanks for the fix. I took a first look and here is some feedback:
It looks like a legit finding. Here is a reproducer: import numpy as np
from sklearn.decomposition import PCA
from sklearn.pipeline import FeatureUnion
from sklearn.preprocessing import FunctionTransformer
X = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
union = FeatureUnion(
[
("pca", PCA(n_components=1)),
("identity", FunctionTransformer()),
]
)
Xt = union.fit_transform(X)
assert Xt.shape == (3, 3)
union
|
@cakedev0 Thanks a lot for looking into this PR and it's great that you found a bug with codex. |
Yeah I'm not too surprised by that ^^ But do you think it can be solved (with a simple enough solution)? Otherwise I think we can merge this PR without fixing it and open an issue to document this bug. That would be ok with me. |
|
@cakedev0 It turns out that if we set Then the output is correct:
I'm not sure if this is considered a bug then. EDIT: This comes from |
|
Well for the snippet I shared, I'd say showing "0 features" below "1 feature" is a bit confusing, showing nothing would be better. That would align with what I think is the current policy: "if we don't know, we don't show". And "1 feature" + "we don't know" = "we don't know"). But maybe I'm missing some context, and that's not what we want to do here. Anyway, as I said, I'm ok not solving that in this PR, we can continue the discussion in a separate issue once this is merged. |
That's right. I got confused myself thinking that setting the Now, to answer the question that if there is an easy fix: I need to think about it, there is not an obvious solution. BTW, I'm trying to fix the codecov failure but I'm not there yet. (Just to tell you I didn't ignore your point 2 above). |
|
At this point a solution could be like follows and improved on a separate PR.
@cakedev0 I'm so sorry I accidentally left today's call when you were talking to me! .. But I figured out the Codecov issue and it's green. Thanks. |
cakedev0
left a comment
There was a problem hiding this comment.
LGTM, thanks!
Two suggestions on the tests, but not blocking.
| class BrokenTransformer(TransformerMixin, BaseEstimator): | ||
| def fit(self, X, y=None): | ||
| self.n_features_in_ = X.shape[1] | ||
| return self | ||
|
|
||
| def get_feature_names_out(self, input_features=None): | ||
| raise RuntimeError("Simulated failure") | ||
|
|
||
| X = np.array([[1, 2], [3, 4]]) | ||
| t = BrokenTransformer() |
There was a problem hiding this comment.
I think you could test that with the FunctionTransformer?
| class BrokenTransformer(TransformerMixin, BaseEstimator): | |
| def fit(self, X, y=None): | |
| self.n_features_in_ = X.shape[1] | |
| return self | |
| def get_feature_names_out(self, input_features=None): | |
| raise RuntimeError("Simulated failure") | |
| X = np.array([[1, 2], [3, 4]]) | |
| t = BrokenTransformer() | |
| X = np.array([[1, 2], [3, 4]]) | |
| t = FunctionTransformer() |
There was a problem hiding this comment.
If I do that, the try/except for a singleblock in estimator.py are skipped so Codecov will complain again.
There was a problem hiding this comment.
Are you sure? t = FunctionTransformer() is a single block too I think.
There was a problem hiding this comment.
Yes, it's a single block but is_fitted_css_class is empty because it's the first estimator I believe.
In any case it doesn't get into try/except, I tested it with the debugger.
| assert "1 feature" in html | ||
| assert "identity" in html |
There was a problem hiding this comment.
| assert "1 feature" in html | |
| assert "identity" in html | |
| assert "1 feature" in html | |
| assert "0 feature" not in html # no misleading "0 feature" at the block level | |
| assert "identity" in html |
There was a problem hiding this comment.
Good idea, thanks.
Just fyi, I had to add <div> 0 features</div> because 0 features was found somewhere else in the documentation area.
I think it's good the way it is now, thanks 👍 no need for improvement IMO.
No worries, yesterday end-of-the-day was very busy for me in the end, so I didn't have time to reach back after that. |
|
We don't need any changelog as long we add in the next release (ping @jeremiedbb). |
|
@copilot resolve the merge conflicts in this pull request Let's if we get somewhere with copilot. |
|
Thank you All! |
Co-authored-by: Guillaume Lemaitre <[email protected]>
Co-authored-by: Guillaume Lemaitre <[email protected]>





Reference Issues/PRs
Fixes #33887
What does this implement/fix? Explain your changes.
We need to check that the meta-estimator has
.get_feature_names_out()before try to display it.TunedThresholdClassifierCVis missing the the visualizer block_sk_visual_block()AI usage disclosure
I used AI assistance for:
Any other comments?