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

Don't fail when pickling models which haven't been trained further #1034

Merged
merged 3 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion skorch/callbacks/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def __getstate__(self):
# don't save away the temporary pbar_ object which gets created on
# epoch begin anew anyway. This avoids pickling errors with tqdm.
state = self.__dict__.copy()
del state['pbar_']
state.pop('pbar_', None)
return state


Expand Down
12 changes: 12 additions & 0 deletions skorch/tests/callbacks/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,18 @@ def test_pickle(self, net_cls, progressbar_cls, data):
net = pickle.loads(dump)
net.fit(*data)

def test_pickle_without_fit(self, net_cls, progressbar_cls, data):
# pickling should work even if the net hasn't been fit.
# see https://github.com/skorch-dev/skorch/pull/1034.
import pickle

net = net_cls(callbacks=[
progressbar_cls(),
])
dump = pickle.dumps(net)

net = pickle.loads(dump)


@pytest.mark.skipif(
not tensorboard_installed, reason='tensorboard is not installed')
Expand Down