Skip to content

Commit

Permalink
Fix Issue 3 (#5)
Browse files Browse the repository at this point in the history
* fix issue #
  • Loading branch information
d-chambers authored Feb 26, 2021
1 parent 6c7a061 commit 20d3c56
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 0 additions & 1 deletion .github/test_conda_env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ dependencies:
- pip
- pip:
- pytest-cov

4 changes: 4 additions & 0 deletions dbscan1d/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def _get_is_core(self, ar):
def _assign_core_group_numbers(self, cores):
""" Given a group of core points, assign group numbers to each. """
gt_eps = abs(cores - np.roll(cores, 1)) > self.eps
# The first value doesn't need to be compared to last, set to False so
# that cluster names are consistent (see issue #3).
if len(gt_eps):
gt_eps[0] = False
return gt_eps.astype(int).cumsum()

def _bound_on(self, arr, max_len):
Expand Down
19 changes: 18 additions & 1 deletion tests/test_dbscan1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def generate_test_data(num_points, centers=None):
# --- tests cases


class TestSKleanEquivilent:
class TestSKleanEquivalent:
"""
Basic tests for DBSCAN1D.
Expand Down Expand Up @@ -109,3 +109,20 @@ def test_blob1_outputs(self, blobs1, db_instances):
assert unclusterd_equal(out1, out2)
# Now assert the same points fall in the same cluster groups
assert clusters_equivalent(out1, out2)


class TestIssues:
"""Tests for issues filled on github."""

def test_issue_3(self):
"""
Test that cluster numbers remain consistent for 1 cluster. See issue #3.
"""
ar1 = [86400.0, 86401.0, 86399.0, 86401.0, 86399.0, 86401.0]
ar2 = [46823, 46818, 46816, 46816, 46819]
dbscan = DBSCAN1D(eps=5, min_samples=3)
# Group names should be sequential, starting with zero
out1 = dbscan.fit_predict(np.array(ar2))
out2 = dbscan.fit_predict(np.array(ar1))
assert set(out1) == {0}
assert set(out2) == {0}

0 comments on commit 20d3c56

Please sign in to comment.