Skip to content

Commit

Permalink
Merge pull request #46 from martinfleis/headtail
Browse files Browse the repository at this point in the history
BUG: RecursiveError in HeadTailBreaks
  • Loading branch information
weikang9009 authored Sep 10, 2019
2 parents cc50f50 + ce4d3a3 commit 1986913
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mapclassify/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def head_tail_breaks(values, cuts):
values = np.array(values)
mean = np.mean(values)
cuts.append(mean)
if len(values) > 1:
if len(set(values)) > 1:
return head_tail_breaks(values[values >= mean], cuts)
return cuts

Expand Down
7 changes: 7 additions & 0 deletions mapclassify/tests/test_mapclassify.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ def test_HeadTail_Breaks(self):
self.assertEqual(len(htb.counts), 4)
np.testing.assert_array_almost_equal(htb.counts, np.array([975, 21, 2, 1]))

def test_HeadTail_Breaks_doublemax(self):
V = np.append(self.V, self.V.max())
htb = HeadTail_Breaks(V)
self.assertEqual(htb.k, 4)
self.assertEqual(len(htb.counts), 4)
np.testing.assert_array_almost_equal(htb.counts, np.array([980, 17, 1, 2]))


class TestMapClassifier(unittest.TestCase):
def test_Map_Classifier(self):
Expand Down

0 comments on commit 1986913

Please sign in to comment.