Open
Description
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.
river/river/preprocessing/ordinal.py
Lines 13 to 14 in 5531ae5
Metadata
Metadata
Assignees
Labels
No labels
Activity