Skip to content

[MRG] Fix appveyor error link to RuntimeWarning #165

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

Merged
merged 16 commits into from
Oct 18, 2016
17 changes: 10 additions & 7 deletions imblearn/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,17 @@ def fit(self, X, y):

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

# Get all the unique elements in the target array
uniques = np.unique(y)

# # Raise an error if there is only one class
# if uniques.size == 1:
# raise RuntimeError("Only one class detected, aborting...")
# Raise a warning for the moment to be compatible with BaseEstimator
if uniques.size == 1:
warnings.warn('Only one class detected, something will get wrong',
RuntimeWarning)
self.logger.debug('The number of classes is %s', np.unique(y).size)
self.logger.debug('Shall we raise a warning: %s',
np.unique(y).size == 1)
if np.unique(y).size == 1:
warnings.simplefilter('always', UserWarning)
warnings.warn('Only one class detected, something will get wrong')
self.logger.debug('The warning should has been raised.')

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

self.logger.info('%s classes detected: %s', uniques.size,
self.logger.info('%s classes detected: %s', np.unique(y).size,
self.stats_c_)

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

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

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

return self
2 changes: 1 addition & 1 deletion imblearn/combine/tests/test_smote_enn.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_smote_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, smote.fit, X, y_single_class)
assert_warns(UserWarning, smote.fit, X, y_single_class)


def test_smote_fit():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/combine/tests/test_smote_tomek.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_smote_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, smote.fit, X, y_single_class)
assert_warns(UserWarning, smote.fit, X, y_single_class)


def test_smote_fit():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/ensemble/tests/test_balance_cascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_bc_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, bc.fit, X, y_single_class)
assert_warns(UserWarning, bc.fit, X, y_single_class)


def test_bc_fit_invalid_ratio():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/ensemble/tests/test_easy_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_ee_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, ee.fit, X, y_single_class)
assert_warns(UserWarning, ee.fit, X, y_single_class)


def test_ee_fit_invalid_ratio():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/over_sampling/tests/test_adasyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_ada_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, ada.fit, X, y_single_class)
assert_warns(UserWarning, ada.fit, X, y_single_class)


def test_ada_fit_invalid_ratio():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/over_sampling/tests/test_random_over_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_ros_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, ros.fit, X, y_single_class)
assert_warns(UserWarning, ros.fit, X, y_single_class)


def test_ros_fit_invalid_ratio():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/over_sampling/tests/test_smote.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_smote_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, smote.fit, X, y_single_class)
assert_warns(UserWarning, smote.fit, X, y_single_class)


def test_smote_fit():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/under_sampling/tests/test_allknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_allknn_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, allknn.fit, X, y_single_class)
assert_warns(UserWarning, allknn.fit, X, y_single_class)


def test_allknn_fit():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/under_sampling/tests/test_cluster_centroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_cc_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, cc.fit, X, y_single_class)
assert_warns(UserWarning, cc.fit, X, y_single_class)


def test_cc_fit_invalid_ratio():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_cnn_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, cnn.fit, X, y_single_class)
assert_warns(UserWarning, cnn.fit, X, y_single_class)


def test_cnn_fit():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_enn_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, enn.fit, X, y_single_class)
assert_warns(UserWarning, enn.fit, X, y_single_class)


def test_enn_fit():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_iht_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, iht.fit, X, y_single_class)
assert_warns(UserWarning, iht.fit, X, y_single_class)


def test_iht_fit_invalid_ratio():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/under_sampling/tests/test_nearmiss_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_nearmiss_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, nm1.fit, X, y_single_class)
assert_warns(UserWarning, nm1.fit, X, y_single_class)


def test_nm_fit_invalid_ratio():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/under_sampling/tests/test_nearmiss_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_nearmiss_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, nm2.fit, X, y_single_class)
assert_warns(UserWarning, nm2.fit, X, y_single_class)


def test_nm_fit_invalid_ratio():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/under_sampling/tests/test_nearmiss_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_nearmiss_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, nm3.fit, X, y_single_class)
assert_warns(UserWarning, nm3.fit, X, y_single_class)


def test_nm_fit_invalid_ratio():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_ncr_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, ncr.fit, X, y_single_class)
assert_warns(UserWarning, ncr.fit, X, y_single_class)


def test_ncr_fit():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/under_sampling/tests/test_one_sided_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_oss_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, oss.fit, X, y_single_class)
assert_warns(UserWarning, oss.fit, X, y_single_class)


def test_oss_fit():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/under_sampling/tests/test_random_under_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_rus_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, rus.fit, X, y_single_class)
assert_warns(UserWarning, rus.fit, X, y_single_class)


def test_rus_fit_invalid_ratio():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_renn_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, renn.fit, X, y_single_class)
assert_warns(UserWarning, renn.fit, X, y_single_class)


def test_renn_fit():
Expand Down
2 changes: 1 addition & 1 deletion imblearn/under_sampling/tests/test_tomek_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_tl_fit_single_class():
# Resample the data
# Create a wrong y
y_single_class = np.zeros((X.shape[0], ))
assert_warns(RuntimeWarning, tl.fit, X, y_single_class)
assert_warns(UserWarning, tl.fit, X, y_single_class)


def test_tl_fit():
Expand Down