8000 FIX Remove validation in FeatureHasher's __init__ by hhnnhh · Pull Request #21573 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

FIX Remove validation in FeatureHasher's __init__ #21573

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 11 commits into from
Dec 14, 2021

Conversation

hhnnhh
Copy link
Contributor
@hhnnhh hhnnhh commented Nov 6, 2021

Reference Issues/PRs

Addresses #21406

What does this implement/fix? Explain your changes.

Removes _validate_params from __init__

Any other comments?

#DataUmbrella

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 @hhnnhh @marenwestermann !

Comment on lines 119 to 120
with pytest.raises(ValueError):
FeatureHasher(input_type="gobbledygook")
FeatureHasher(input_type="gobbledygook").transform(raw_X)
Copy link
Member

Choose a reason for hiding this comment

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

To make sure that FeatureHasher raises during transform and not __init__:

    h = FeatureHasher(input_type="gobbledygook")
    with pytest.raises(ValueError):
        h.transform(raw_X)

Same comment applies to the changes below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your comment. We have changed the test accordingly.

@thomasjpfan thomasjpfan changed the title remove _validate_params from __init__ FIX Remove validation in FeatureHasher's init Nov 24, 2021
@thomasjpfan thomasjpfan changed the title FIX Remove validation in FeatureHasher's init FIX Remove validation in FeatureHasher's __init__ Nov 24, 2021
< 8000 div class="timeline-comment-header clearfix d-flex" data-morpheus-enabled="false">
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.

Small nit about the whats new, otherwise LGTM!

Comment on lines 102 to 103
- |Fix| :class:`feature_extraction.FeatureHasher` now validates input parameters in `transform` instead of `__init__`.
:pr:`21573` by :user:`Hannah Bohle <hhnnhh>` and :user:`Maren Westermann <marenwestermann>`.
Copy link
Member

Choose a reason for hiding this comment

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

To be consistent with the rest of the file, we can wrap the text here:

- |Fix| :class:`feature_extraction.FeatureHasher` now validates input parameters
  in `transform` instead of `__init__`. :pr:`21573` by
  :user:`Hannah Bohle <hhnnhh>` and :user:`Maren Westermann <marenwestermann>`.

@reshamas
Copy link
Member
reshamas commented Dec 2, 2021

@hhnnhh @marenwestermann
In case you have questions on the PR. Can you make it to the next office hours for scikit-learn? Info is below.


Hi all,

Some of us will be online on the scikit-learn discord Monday December 6 at
10:00 PT / 13:00 ET / 18:00 UTC / 19:00 CET for about an hour or so.

First time and occasional contributors are welcome to join us to
discord using this invitation link:
https://discord.gg/YyYRXMju https://discord.gg/YyYRXMju

The focus of these office hour sessions is to answer questions about
contributing to scikit-learn. We can also split into break out
audio/text channels and do pair programming or live reviewing of
forgotten pull requests with screen sharing.

We can also try to assist you into crafting minimal reproduction cases
for bug reports to get a higher likelihood of resolution (e.g.
https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports https://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

Please note, our Code of Conduct applies:
https://github.com/scikit-learn/scikit-learn/blob/main/CODE_OF_CONDUCT.md https://github.com/scikit-learn/scikit-learn/blob/main/CODE_OF_CONDUCT.md

@@ -114,14 +114,20 @@ def test_hash_empty_input():


def test_hasher_invalid_input():
raw_X = [[], (), iter(range(0))]

h = FeatureHasher(input_type="gobbledygook")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
h = FeatureHasher(input_type="gobbledygook")
feature_hasher = FeatureHasher(input_type="gobbledygook")

Copy link
Member

Choose a reason for hiding this comment

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

and then reusing this variable afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @glemaitre for your suggestions. We changed the variable name accordingly.

@glemaitre glemaitre merged commit 4b5ea12 into scikit-learn:main Dec 14, 2021
@glemaitre
Copy link
Member

LGTM. Thanks @hhnnhh @marenwestermann

@hhnnhh hhnnhh deleted the featurehasher branch December 17, 2021 13:12
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.

6 participants
0