Skip to content

Commit 12ac7d8

Browse files
author
Guillaume Lemaitre
committed
implement setstate for the pickle
1 parent 19be425 commit 12ac7d8

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

imblearn/base.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, ratio='auto'):
4747
"""
4848

4949
self.ratio = ratio
50-
50+
self.logger = logging.getLogger(__name__)
5151

5252
def fit(self, X, y):
5353
"""Find the classes statistics before to perform sampling.
@@ -69,8 +69,6 @@ def fit(self, X, y):
6969

7070
# Check the consistency of X and y
7171
X, y = check_X_y(X, y)
72-
73-
self._get_logger()
7472

7573
self.min_c_ = None
7674
self.maj_c_ = None
@@ -140,8 +138,6 @@ def sample(self, X, y):
140138

141139
# Check the consistency of X and y
142140
X, y = check_X_y(X, y)
143-
144-
self._get_logger()
145141

146142
# Check that the data have been fitted
147143
if not hasattr(self, 'stats_c_'):
@@ -220,11 +216,13 @@ def _sample(self, X, y):
220216
pass
221217

222218
def __getstate__(self):
223-
"""Prevent logger from being pickled"""
219+
"""Prevent logger from being pickled."""
224220
object_dictionary = self.__dict__.copy()
225221
del object_dictionary['logger']
226222
return object_dictionary
227223

228-
229-
def _get_logger(self):
230-
self.logger = logging.getLogger(__name__)
224+
def __setstate__(self, dict):
225+
"""Re-open the logger."""
226+
logger = logging.getLogger(__name__)
227+
self.__dict__.update(dict)
228+
self.logger = logger

0 commit comments

Comments
 (0)