8000 'feature_name' referenced before assignment · Issue #19489 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

'feature_name' referenced before assignment #19489

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

Closed
FloHu opened this issue Feb 18, 2021 · 2 comments · Fixed by #19520
Closed

'feature_name' referenced before assignment #19489

FloHu opened this issue Feb 18, 2021 · 2 comments · Fixed by #19520

Comments

@FloHu
Copy link
FloHu commented Feb 18, 2021

Describe the bug

When I run some preprocessing on my data the line triggering the error is:

C:\local_tools\Anaconda3\envs\mother_env\lib\site-packages\sklearn\feature_extraction\_dict_vectorizer.py in _transform(self, X, fitting)
    226                                                indices=indices, values=values)
    227 
--> 228                 if feature_name is not None:
    229                     if fitting and feature_name not in vocab:
    230                         vocab[feature_name] = len(feature_names)

UnboundLocalError: local variable 'feature_name' referenced before assignment

Steps/Code to Reproduce

It involves a bit too much preprocessing to put here but from inspecting the respective source file (see above, sklearn\feature_extraction_dict_vectorizer.py) I have the strong suspicion that feature_name can go through all if/elif checks without being assigned anything.

Versions

System:
python: 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)]
executable: C:\local_tools\Anaconda3\envs\mother_env\python.exe
machine: Windows-10-10.0.18362-SP0

Python dependencies:
pip: 20.3.3
setuptools: 52.0.0.post20210125
sklearn: 0.24.1
numpy: 1.19.2
scipy: 1.6.0
Cython: None
pandas: 1.2.1
matplotlib: 3.3.4
joblib: 1.0.1
threadpoolctl: 2.1.0

Built with OpenMP: True

@NicolasHug
Copy link
Member

It involves a bit too much preprocessing to put here

Could you trim it down to something that still reproduces the issue?

@FloHu
Copy link
Author
FloHu commented Feb 22, 2021

It involves a bit too much preprocessing to put here

Could you trim it down to something that still reproduces the issue?

Sorry for the late answer. I will try to. I also noticed that it seems to be a regression, with sklearn version 0.23 the error is not there.

Thanks @kamiyaa for the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0