Skip to content
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

Cannot pickle preprocessing.OrdinalEncoder instance #1662

Open
Bing-su opened this issue Dec 11, 2024 · 1 comment
Open

Cannot pickle preprocessing.OrdinalEncoder instance #1662

Bing-su opened this issue Dec 11, 2024 · 1 comment

Comments

@Bing-su
Copy link

Bing-su commented Dec 11, 2024

river version: 0.22.0
Python version: 3.10.12 (google colab)
Operating system: Linux (google colab)

Describe the bug

Cannot pickle preprocessing.OrdinalEncoder instance

Steps/code to reproduce

import pickle

from river import preprocessing

X = [
    {"country": "France", "place": "Taco Bell"},
    {"country": None, "place": None},
    {"country": "Sweden", "place": "Burger King"},
    {"country": "France", "place": "Burger King"},
    {"country": "Russia", "place": "Starbucks"},
    {"country": "Russia", "place": "Starbucks"},
    {"country": "Sweden", "place": "Taco Bell"},
    {"country": None, "place": None},
]

encoder = preprocessing.OrdinalEncoder()
for x in X:
    print(encoder.transform_one(x))
    encoder.learn_one(x)

with open("encoder.pkl", "wb") as f:
    pickle.dump(encoder, f)
{'country': 0, 'place': 0}
{'country': -1, 'place': -1}
{'country': 0, 'place': 0}
{'country': 1, 'place': 2}
{'country': 0, 'place': 0}
{'country': 3, 'place': 3}
{'country': 2, 'place': 1}
{'country': -1, 'place': -1}

---------------------------------------------------------------------------

TypeError                                 Traceback (most recent call last)

[<ipython-input-3-fa4773e7a2b5>](https://localhost:8080/#) in <cell line: 21>()
     20 
     21 with open("encoder.pkl", "wb") as f:
---> 22     pickle.dump(encoder, f)

TypeError: cannot pickle 'generator' object

The problematic generator seems to be this one.

def make_counter(skip):
return (i for i in itertools.count() if i not in skip)

@MaxHalford
Copy link
Member

Good catch!

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

No branches or pull requests

2 participants