Skip to content

Commit 23c0b4c

Browse files
authored
[MRG] Fix appveyor error link to RuntimeWarning (#165)
* Change the unique checking * Change type of warning * Change runtimewarning to userwarning * Set the warnings filters * Add some debugging * Downgrade python * add some dbg * avoid capturing the warning in logger * Make crippy test * Create the warning 2 subclasses * solve an error * check if we remove something that rise somethign before * Try something else * try to force the raising * add the check estimator again * reset appveyor
1 parent daba53a commit 23c0b4c

21 files changed

+30
-27
lines changed

imblearn/base.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,17 @@ def fit(self, X, y):
7676

7777
self.logger.info('Compute classes statistics ...')
7878

79-
# Get all the unique elements in the target array
80-
uniques = np.unique(y)
81-
8279
# # Raise an error if there is only one class
8380
# if uniques.size == 1:
8481
# raise RuntimeError("Only one class detected, aborting...")
8582
# Raise a warning for the moment to be compatible with BaseEstimator
86-
if uniques.size == 1:
87-
warnings.warn('Only one class detected, something will get wrong',
88-
RuntimeWarning)
83+
self.logger.debug('The number of classes is %s', np.unique(y).size)
84+
self.logger.debug('Shall we raise a warning: %s',
85+
np.unique(y).size == 1)
86+
if np.unique(y).size == 1:
87+
warnings.simplefilter('always', UserWarning)
88+
warnings.warn('Only one class detected, something will get wrong')
89+
self.logger.debug('The warning should has been raised.')
8990

9091
# Store the size of X to check at sampling time if we have the
9192
# same data
@@ -98,7 +99,7 @@ def fit(self, X, y):
9899
self.min_c_ = min(self.stats_c_, key=self.stats_c_.get)
99100
self.maj_c_ = max(self.stats_c_, key=self.stats_c_.get)
100101

101-
self.logger.info('%s classes detected: %s', uniques.size,
102+
self.logger.info('%s classes detected: %s', np.unique(y).size,
102103
self.stats_c_)
103104

104105
# Check if the ratio provided at initialisation make sense
@@ -254,6 +255,7 @@ def fit(self, X, y):
254255

255256
# Check that the target type is binary
256257
if not type_of_target(y) == 'binary':
258+
warnings.simplefilter('always', UserWarning)
257259
warnings.warn('The target type should be binary.')
258260

259261
return self
@@ -290,6 +292,7 @@ def fit(self, X, y):
290292
# Check that the target type is either binary or multiclass
291293
if not (type_of_target(y) == 'binary' or
292294
type_of_target(y) == 'multiclass'):
295+
warnings.simplefilter('always', UserWarning)
293296
warnings.warn('The target type should be binary or multiclass.')
294297

295298
return self

imblearn/combine/tests/test_smote_enn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_smote_fit_single_class():
7474
# Resample the data
7575
# Create a wrong y
7676
y_single_class = np.zeros((X.shape[0], ))
77-
assert_warns(RuntimeWarning, smote.fit, X, y_single_class)
77+
assert_warns(UserWarning, smote.fit, X, y_single_class)
7878

7979

8080
def test_smote_fit():

imblearn/combine/tests/test_smote_tomek.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_smote_fit_single_class():
7474
# Resample the data
7575
# Create a wrong y
7676
y_single_class = np.zeros((X.shape[0], ))
77-
assert_warns(RuntimeWarning, smote.fit, X, y_single_class)
77+
assert_warns(UserWarning, smote.fit, X, y_single_class)
7878

7979

8080
def test_smote_fit():

imblearn/ensemble/tests/test_balance_cascade.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def test_bc_fit_single_class():
9090
# Resample the data
9191
# Create a wrong y
9292
y_single_class = np.zeros((X.shape[0], ))
93-
assert_warns(RuntimeWarning, bc.fit, X, y_single_class)
93+
assert_warns(UserWarning, bc.fit, X, y_single_class)
9494

9595

9696
def test_bc_fit_invalid_ratio():

imblearn/ensemble/tests/test_easy_ensemble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_ee_fit_single_class():
8181
# Resample the data
8282
# Create a wrong y
8383
y_single_class = np.zeros((X.shape[0], ))
84-
assert_warns(RuntimeWarning, ee.fit, X, y_single_class)
84+
assert_warns(UserWarning, ee.fit, X, y_single_class)
8585

8686

8787
def test_ee_fit_invalid_ratio():

imblearn/over_sampling/tests/test_adasyn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def test_ada_fit_single_class():
8484
# Resample the data
8585
# Create a wrong y
8686
y_single_class = np.zeros((X.shape[0], ))
87-
assert_warns(RuntimeWarning, ada.fit, X, y_single_class)
87+
assert_warns(UserWarning, ada.fit, X, y_single_class)
8888

8989

9090
def test_ada_fit_invalid_ratio():

imblearn/over_sampling/tests/test_random_over_sampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_ros_fit_single_class():
7575
# Resample the data
7676
# Create a wrong y
7777
y_single_class = np.zeros((X.shape[0], ))
78-
assert_warns(RuntimeWarning, ros.fit, X, y_single_class)
78+
assert_warns(UserWarning, ros.fit, X, y_single_class)
7979

8080

8181
def test_ros_fit_invalid_ratio():

imblearn/over_sampling/tests/test_smote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_smote_fit_single_class():
8383
# Resample the data
8484
# Create a wrong y
8585
y_single_class = np.zeros((X.shape[0], ))
86-
assert_warns(RuntimeWarning, smote.fit, X, y_single_class)
86+
assert_warns(UserWarning, smote.fit, X, y_single_class)
8787

8888

8989
def test_smote_fit():

imblearn/under_sampling/tests/test_allknn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def test_allknn_fit_single_class():
8383
# Resample the data
8484
# Create a wrong y
8585
y_single_class = np.zeros((X.shape[0], ))
86-
assert_warns(RuntimeWarning, allknn.fit, X, y_single_class)
86+
assert_warns(UserWarning, allknn.fit, X, y_single_class)
8787

8888

8989
def test_allknn_fit():

imblearn/under_sampling/tests/test_cluster_centroids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_cc_fit_single_class():
7878
# Resample the data
7979
# Create a wrong y
8080
y_single_class = np.zeros((X.shape[0], ))
81-
assert_warns(RuntimeWarning, cc.fit, X, y_single_class)
81+
assert_warns(UserWarning, cc.fit, X, y_single_class)
8282

8383

8484
def test_cc_fit_invalid_ratio():

imblearn/under_sampling/tests/test_condensed_nearest_neighbour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_cnn_fit_single_class():
6060
# Resample the data
6161
# Create a wrong y
6262
y_single_class = np.zeros((X.shape[0], ))
63-
assert_warns(RuntimeWarning, cnn.fit, X, y_single_class)
63+
assert_warns(UserWarning, cnn.fit, X, y_single_class)
6464

6565

6666
def test_cnn_fit():

imblearn/under_sampling/tests/test_edited_nearest_neighbours.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_enn_fit_single_class():
6161
# Resample the data
6262
# Create a wrong y
6363
y_single_class = np.zeros((X.shape[0], ))
64-
assert_warns(RuntimeWarning, enn.fit, X, y_single_class)
64+
assert_warns(UserWarning, enn.fit, X, y_single_class)
6565

6666

6767
def test_enn_fit():

imblearn/under_sampling/tests/test_instance_hardness_threshold.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def test_iht_fit_single_class():
9393
# Resample the data
9494
# Create a wrong y
9595
y_single_class = np.zeros((X.shape[0], ))
96-
assert_warns(RuntimeWarning, iht.fit, X, y_single_class)
96+
assert_warns(UserWarning, iht.fit, X, y_single_class)
9797

9898

9999
def test_iht_fit_invalid_ratio():

imblearn/under_sampling/tests/test_nearmiss_1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_nearmiss_fit_single_class():
9797
# Resample the data
9898
# Create a wrong y
9999
y_single_class = np.zeros((X.shape[0], ))
100-
assert_warns(RuntimeWarning, nm1.fit, X, y_single_class)
100+
assert_warns(UserWarning, nm1.fit, X, y_single_class)
101101

102102

103103
def test_nm_fit_invalid_ratio():

imblearn/under_sampling/tests/test_nearmiss_2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_nearmiss_fit_single_class():
9797
# Resample the data
9898
# Create a wrong y
9999
y_single_class = np.zeros((X.shape[0], ))
100-
assert_warns(RuntimeWarning, nm2.fit, X, y_single_class)
100+
assert_warns(UserWarning, nm2.fit, X, y_single_class)
101101

102102

103103
def test_nm_fit_invalid_ratio():

imblearn/under_sampling/tests/test_nearmiss_3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def test_nearmiss_fit_single_class():
9797
# Resample the data
9898
# Create a wrong y
9999
y_single_class = np.zeros((X.shape[0], ))
100-
assert_warns(RuntimeWarning, nm3.fit, X, y_single_class)
100+
assert_warns(UserWarning, nm3.fit, X, y_single_class)
101101

102102

103103
def test_nm_fit_invalid_ratio():

imblearn/under_sampling/tests/test_neighbourhood_cleaning_rule.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_ncr_fit_single_class():
5555
# Resample the data
5656
# Create a wrong y
5757
y_single_class = np.zeros((X.shape[0], ))
58-
assert_warns(RuntimeWarning, ncr.fit, X, y_single_class)
58+
assert_warns(UserWarning, ncr.fit, X, y_single_class)
5959

6060

6161
def test_ncr_fit():

imblearn/under_sampling/tests/test_one_sided_selection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def test_oss_fit_single_class():
5757
# Resample the data
5858
# Create a wrong y
5959
y_single_class = np.zeros((X.shape[0], ))
60-
assert_warns(RuntimeWarning, oss.fit, X, y_single_class)
60+
assert_warns(UserWarning, oss.fit, X, y_single_class)
6161

6262

6363
def test_oss_fit():

imblearn/under_sampling/tests/test_random_under_sampler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def test_rus_fit_single_class():
7474
# Resample the data
7575
# Create a wrong y
7676
y_single_class = np.zeros((X.shape[0], ))
77-
assert_warns(RuntimeWarning, rus.fit, X, y_single_class)
77+
assert_warns(UserWarning, rus.fit, X, y_single_class)
7878

7979

8080
def test_rus_fit_invalid_ratio():

imblearn/under_sampling/tests/test_repeated_edited_nearest_neighbours.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_renn_fit_single_class():
9494
# Resample the data
9595
# Create a wrong y
9696
y_single_class = np.zeros((X.shape[0], ))
97-
assert_warns(RuntimeWarning, renn.fit, X, y_single_class)
97+
assert_warns(UserWarning, renn.fit, X, y_single_class)
9898

9999

100100
def test_renn_fit():

imblearn/under_sampling/tests/test_tomek_links.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_tl_fit_single_class():
5959
# Resample the data
6060
# Create a wrong y
6161
y_single_class = np.zeros((X.shape[0], ))
62-
assert_warns(RuntimeWarning, tl.fit, X, y_single_class)
62+
assert_warns(UserWarning, tl.fit, X, y_single_class)
6363

6464

6565
def test_tl_fit():

0 commit comments

Comments
 (0)