Skip to content

Commit

Permalink
Merge pull request #1361 from astaric/py3k
Browse files Browse the repository at this point in the history
FIX Python 3 compatibility
  • Loading branch information
ogrisel committed Nov 14, 2012
2 parents e3fc34a + 9496a96 commit a345761
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion sklearn/linear_model/base.py
Expand Up @@ -25,7 +25,7 @@
from ..utils.fixes import lsqr
from ..utils.sparsefuncs import (csc_mean_variance_axis0,
inplace_csc_column_scale)
from cd_fast import sparse_std
from .cd_fast import sparse_std


###
Expand Down
2 changes: 1 addition & 1 deletion sklearn/mixture/tests/test_gmm.py
Expand Up @@ -185,7 +185,7 @@ def test_sample(self, n=100):
g.weights_ = self.weights

samples = g.sample(n)
self.assertEquals(samples.shape, (n, self.n_features))
self.assertEqual(samples.shape, (n, self.n_features))

def test_train(self, params='wmc'):
g = mixture.GMM(n_components=self.n_components,
Expand Down
16 changes: 8 additions & 8 deletions sklearn/tests/test_hmm.py
Expand Up @@ -173,7 +173,7 @@ def test_base_hmm_attributes(self):

h = self.StubHMM(n_components)

self.assertEquals(h.n_components, n_components)
self.assertEqual(h.n_components, n_components)

h.startprob_ = startprob
assert_array_almost_equal(h.startprob_, startprob)
Expand Down Expand Up @@ -270,7 +270,7 @@ def test_sample(self, n=1000):
h.startprob_ = self.startprob

samples = h.sample(n)[0]
self.assertEquals(samples.shape, (n, self.n_features))
self.assertEqual(samples.shape, (n, self.n_features))

def test_fit(self, params='stmc', n_iter=5, verbose=False, **kwargs):
h = hmm.GaussianHMM(self.n_components, self.covariance_type)
Expand Down Expand Up @@ -456,7 +456,7 @@ def test_predict(self):
def test_attributes(self):
h = hmm.MultinomialHMM(self.n_components)

self.assertEquals(h.n_components, self.n_components)
self.assertEqual(h.n_components, self.n_components)

h.startprob_ = self.startprob
assert_array_almost_equal(h.startprob_, self.startprob)
Expand All @@ -479,7 +479,7 @@ def test_attributes(self):
self.assertRaises(ValueError, h.__setattr__, 'emissionprob_', [])
self.assertRaises(ValueError, h.__setattr__, 'emissionprob_',
np.zeros((self.n_components - 2, self.n_symbols)))
self.assertEquals(h.n_symbols, self.n_symbols)
self.assertEqual(h.n_symbols, self.n_symbols)

def test_eval(self):
idx = np.repeat(range(self.n_components), 10)
Expand All @@ -493,8 +493,8 @@ def test_eval(self):

def test_sample(self, n=1000):
samples = self.h.sample(n)[0]
self.assertEquals(len(samples), n)
self.assertEquals(len(np.unique(samples)), self.n_symbols)
self.assertEqual(len(samples), n)
self.assertEqual(len(np.unique(samples)), self.n_symbols)

def test_fit(self, params='ste', n_iter=5, verbose=False, **kwargs):
h = self.h
Expand Down Expand Up @@ -586,7 +586,7 @@ def setUp(self):
def test_attributes(self):
h = hmm.GMMHMM(self.n_components, covariance_type=self.covariance_type)

self.assertEquals(h.n_components, self.n_components)
self.assertEqual(h.n_components, self.n_components)

h.startprob_ = self.startprob
assert_array_almost_equal(h.startprob_, self.startprob)
Expand Down Expand Up @@ -628,7 +628,7 @@ def test_sample(self, n=1000):
startprob=self.startprob, transmat=self.transmat,
gmms=self.gmms)
samples = h.sample(n)[0]
self.assertEquals(samples.shape, (n, self.n_features))
self.assertEqual(samples.shape, (n, self.n_features))

def test_fit(self, params='stmwc', n_iter=5, verbose=False, **kwargs):
h = hmm.GMMHMM(self.n_components, covars_prior=1.0)
Expand Down
8 changes: 2 additions & 6 deletions sklearn/tests/test_naive_bayes.py
Expand Up @@ -92,16 +92,12 @@ def test_discretenb_pickle():
clf = cls().fit(X2, y2)
y_pred = clf.predict(X2)

store = StringIO()
store = BytesIO()
pickle.dump(clf, store)
clf = pickle.load(StringIO(store.getvalue()))
clf = pickle.load(BytesIO(store.getvalue()))

assert_array_equal(y_pred, clf.predict(X2))

store = BytesIO()
pickle.dump(clf, store)
clf = pickle.load(BytesIO(store.getvalue()))


def test_input_check():
"""Test input checks"""
Expand Down
1 change: 1 addition & 0 deletions sklearn/utils/fixes.py
Expand Up @@ -107,6 +107,7 @@ def _unique(ar, return_index=False, return_inverse=False):
except ValueError:
# x may be of the form dev-1ea1592
np_version.append(x)
np_version = tuple(np_version)

if np_version[:2] < (1, 5):
unique = _unique
Expand Down

0 comments on commit a345761

Please sign in to comment.