Skip to content

Commit

Permalink
more style updates
Browse files Browse the repository at this point in the history
  • Loading branch information
nicodv committed Feb 26, 2022
1 parent 10fbbf5 commit 02f76d0
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 26 deletions.
7 changes: 3 additions & 4 deletions .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ strictness: high
max-line-length: 90
ignore-paths:
- setup.py
- examples/
- .github/
- examples
- .github
python-targets:
- 3
pep8:
Expand All @@ -23,5 +23,4 @@ pylint:
min-public-methods: 1
bandit:
options:
skips:
- B301
skips: ['B301']
5 changes: 2 additions & 3 deletions kmodes/kmodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ def predict(self, X, **kwargs):
def cluster_centroids_(self):
if hasattr(self, '_enc_cluster_centroids'):
return decode_centroids(self._enc_cluster_centroids, self._enc_map)
else:
raise AttributeError("'{}' object has no attribute 'cluster_centroids_' "
"because the model is not yet fitted.")
raise AttributeError("'{}' object has no attribute 'cluster_centroids_' "
"because the model is not yet fitted.")


def labels_cost(X, centroids, dissim, membship=None):
Expand Down
7 changes: 3 additions & 4 deletions kmodes/kprototypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
K-prototypes clustering for mixed categorical and numerical data
"""

# pylint: disable=super-on-old-class,unused-argument,attribute-defined-outside-init
# pylint: disable=unused-argument,attribute-defined-outside-init

from collections import defaultdict

Expand Down Expand Up @@ -203,9 +203,8 @@ def cluster_centroids_(self):
self._enc_cluster_centroids[0],
decode_centroids(self._enc_cluster_centroids[1], self._enc_map)
))
else:
raise AttributeError("'{}' object has no attribute 'cluster_centroids_' "
"because the model is not yet fitted.")
raise AttributeError("'{}' object has no attribute 'cluster_centroids_' "
"because the model is not yet fitted.")


def labels_cost(Xnum, Xcat, centroids, num_dissim, cat_dissim, gamma, membship=None):
Expand Down
2 changes: 1 addition & 1 deletion kmodes/tests/test_kmodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def find_splits(x):
np.testing.assert_array_equal(find_splits(array1), find_splits(array2))


# pylint: disable=R0201,W0105
# pylint: disable=no-self-use,pointless-statement
class TestKModes(unittest.TestCase):

def test_pickle(self):
Expand Down
2 changes: 1 addition & 1 deletion kmodes/tests/test_kprototypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
])


# pylint: disable=R0201,W0105
# pylint: disable=no-self-use,pointless-statement
class TestKProtoTypes(unittest.TestCase):

def test_pickle(self):
Expand Down
8 changes: 4 additions & 4 deletions kmodes/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ def get_max_value_key(dic):
maxima = np.where(v == np.max(v))[0]
if len(maxima) == 1:
return k[maxima[0]]
else:
# In order to be consistent, always selects the minimum key
# (guaranteed to be unique) when there are multiple maximum values.
return k[maxima[np.argmin(k[maxima])]]

# In order to be consistent, always selects the minimum key
# (guaranteed to be unique) when there are multiple maximum values.
return k[maxima[np.argmin(k[maxima])]]


def encode_features(X, enc_map=None):
Expand Down
11 changes: 5 additions & 6 deletions kmodes/util/dissim.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def jaccard_dissim_binary(a, b, **__):
denominator = np.sum(np.bitwise_or(a, b), axis=1)
if (denominator == 0).any(0):
raise ValueError("Insufficient Number of data since union is 0")
else:
return 1 - numerator / denominator
return 1 - numerator / denominator
raise ValueError("Missing or non Binary values detected in Binary columns.")


Expand All @@ -28,11 +27,11 @@ def jaccard_dissim_label(a, b, **__):
raise ValueError("Missing values detected in Numeric columns.")
intersect_len = np.empty(len(a), dtype=int)
union_len = np.empty(len(a), dtype=int)
i = 0
ii = 0
for row in a:
intersect_len[i] = len(np.intersect1d(row, b))
union_len[i] = len(np.unique(row)) + len(np.unique(b)) - intersect_len[i]
i += 1
intersect_len[ii] = len(np.intersect1d(row, b))
union_len[ii] = len(np.unique(row)) + len(np.unique(b)) - intersect_len[ii]
ii += 1
if (union_len == 0).any():
raise ValueError("Insufficient Number of data since union is 0")
return 1 - intersect_len / union_len
Expand Down
2 changes: 1 addition & 1 deletion kmodes/util/tests/test_dissim.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from kmodes.util.dissim import jaccard_dissim_binary, jaccard_dissim_label


# pylint: disable=R0201,W0105
# pylint: disable=no-self-use,pointless-statement
class TestDissimilarityMeasures(unittest.TestCase):

def test_matching_dissim(self):
Expand Down
2 changes: 1 addition & 1 deletion kmodes/util/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
])


# pylint: disable=R0201,W0105
# pylint: disable=no-self-use,pointless-statement
class TestUtils(unittest.TestCase):

def test_get_max_value_key(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

VERSION = kmodes.__version__

with open('README.rst', 'r') as readme_file:
with open('README.rst', encoding='utf8') as readme_file:
README = readme_file.read()

setup(
Expand Down

0 comments on commit 02f76d0

Please sign in to comment.