Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions mapclassify/tests/test_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

def _assertions(a, b):
assert a.k == b.k
assert a.yb.all() == b.yb.all()
assert a.bins.all() == b.bins.all()
assert a.counts.all() == b.counts.all()
assert (a.yb == b.yb).all()
assert (a.bins == b.bins).all()
assert (a.counts == b.counts).all()


class TestClassify:
Expand All @@ -33,6 +33,12 @@ def test_fisher_jenks(self):
b = mapclassify.FisherJenks(self.x, k=3)
_assertions(a, b)

# mapclassify\classifiers.py:FisherJenksSampled.__init__
# 2028 ids = np.random.randint(0, n, int(n * pct))
@pytest.mark.xfail(
reason="Stochastic. Passing a.s. requires random samples "
"to be the same in both instances. "
)
def test_fisher_jenks_sampled(self):
a = mapclassify.classify(
self.x, "FisherJenksSampled", k=3, pct_sampled=0.5, truncate=False
Expand Down Expand Up @@ -69,16 +75,34 @@ def test_jenks_caspall_forced(self):
b = mapclassify.JenksCaspallForced(self.x, k=3)
_assertions(a, b)

# mapclassify\classifiers.py:JenksCaspallSampled.__init__
# 2224 ids = np.random.randint(0, n, int(n * pct))
@pytest.mark.xfail(
reason="Stochastic. Passing a.s. requires random samples "
"to be the same in both instances. "
)
def test_jenks_caspall_sampled(self):
a = mapclassify.classify(self.x, "JenksCaspallSampled", pct_sampled=0.5)
b = mapclassify.JenksCaspallSampled(self.x, pct=0.5)
_assertions(a, b)

# KMeans iterates starting from a randomly generated centroids
@pytest.mark.xfail(
reason="Stochastic. Passing a.s. requires random centroids "
"to be the same in both instances. "
)
def test_natural_breaks(self):
a = mapclassify.classify(self.x, "natural_breaks")
b = mapclassify.NaturalBreaks(self.x)
_assertions(a, b)

# mapclassify\classifiers.py:MaxP._set_bins
# 2656 rseeds = np.random.permutation(list(range(k))).tolist()
# 2701 rseeds = np.random.permutation(list(range(k))).tolist()
@pytest.mark.xfail(
reason="Stochastic. Passing a.s. requires random selections "
"to be the same in both instances. "
)
def test_max_p_classifier(self):
a = mapclassify.classify(self.x, "max_p", k=3, initial=50)
b = mapclassify.MaxP(self.x, k=3, initial=50)
Expand Down