Skip to content

Commit

Permalink
add pandas-numpy equality test
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodv committed Jun 24, 2022
1 parent fe1a473 commit f5532e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kmodes/tests/test_kmodes.py
Expand Up @@ -6,6 +6,7 @@
import unittest

import numpy as np
import pandas as pd

from kmodes.kmodes import KModes
from kmodes.util.dissim import ng_dissim, jaccard_dissim_binary, jaccard_dissim_label
Expand Down Expand Up @@ -575,3 +576,9 @@ def test_kmodes_fit_predict(self):
data1 = kmodes.fit_predict(TEST_DATA, sample_weight=sample_weight)
data2 = kmodes.fit(TEST_DATA, sample_weight=sample_weight).predict(TEST_DATA)
assert_cluster_splits_equal(data1, data2)

def test_pandas_numpy_equality(self):
kmodes = KModes(n_clusters=4, init='Cao', random_state=42)
result_np = kmodes.fit_predict(SOYBEAN)
result_pd = kmodes.fit_predict(pd.DataFrame(SOYBEAN))
np.testing.assert_array_equal(result_np, result_pd)
7 changes: 7 additions & 0 deletions kmodes/tests/test_kprototypes.py
Expand Up @@ -6,6 +6,7 @@
import unittest

import numpy as np
import pandas as pd

from kmodes import kprototypes
from kmodes.tests.test_kmodes import assert_cluster_splits_equal
Expand Down Expand Up @@ -421,3 +422,9 @@ def test_kmodes_fit_predict_equality(self):
data1 = model1.predict(STOCKS, categorical=[1, 2])
data2 = kproto.fit_predict(STOCKS, categorical=[1, 2], sample_weight=sample_weight)
assert_cluster_splits_equal(data1, data2)

def test_pandas_numpy_equality(self):
kproto = kprototypes.KPrototypes(n_clusters=4, init='Cao', random_state=42)
result_np = kproto.fit_predict(STOCKS, categorical=[1, 2])
result_pd = kproto.fit_predict(pd.DataFrame(STOCKS), categorical=[1, 2])
np.testing.assert_array_equal(result_np, result_pd)
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -34,6 +34,7 @@
'dev': [
'pytest',
'pytest-cov',
'pandas'
]
},
classifiers=['Development Status :: 3 - Alpha',
Expand Down

0 comments on commit f5532e0

Please sign in to comment.