Skip to content

Cannot pickle preprocessing.OrdinalEncoder instance #1662

Open
@Bing-su

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.

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions