Repository: motiwari/BanditPAM (language: python)

Issue:
Should rename `final_medoids` attribute of `KMedoids` object to `medoids`
The term `final_medoids` is confusing and counterintuitive; it's unlikely anyone will use the `build_medoids`, so we should rename `final_medoids` to `medoids`


Discussion / hints:

Fix patch:
diff --git a/README.md b/README.md
index 9217b2e0..48259aa4 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ kmed.fit(X, 'L2', 3, "gmm_log")
 
 # Visualize the data and the medoids:
 for p_idx, point in enumerate(X):
-    if p_idx in map(int, kmed.final_medoids):
+    if p_idx in map(int, kmed.medoids):
         plt.scatter(X[p_idx, 0], X[p_idx, 1], color='red', s = 40)
     else:
         plt.scatter(X[p_idx, 0], X[p_idx, 1], color='blue', s = 10)
@@ -92,7 +92,7 @@ kmed.fit(X, 'L2', 10, "mnist_log")
 
 # Visualize the data and the medoids via t-SNE:
 for p_idx, point in enumerate(X):
-    if p_idx in map(int, kmed.final_medoids):
+    if p_idx in map(int, kmed.medoids):
         plt.scatter(X_tsne[p_idx, 0], X_tsne[p_idx, 1], color='red', s = 40)
     else:
         plt.scatter(X_tsne[p_idx, 0], X_tsne[p_idx, 1], color='blue', s = 5)
diff --git a/src/kmeds_pywrapper.cpp b/src/kmeds_pywrapper.cpp
index 0d2b29ef..1bd2894e 100644
--- a/src/kmeds_pywrapper.cpp
+++ b/src/kmeds_pywrapper.cpp
@@ -100,7 +100,7 @@ PYBIND11_MODULE(BanditPAM, m) {
       .def_property("verbosity", &KMedsWrapper::getVerbosity, &KMedsWrapper::setVerbosity)
       .def_property("maxIter", &KMedsWrapper::getMaxIter, &KMedsWrapper::setMaxIter)
       .def_property("logFilename", &KMedsWrapper::getLogfileName, &KMedsWrapper::setLogFilename)
-      .def_property_readonly("final_medoids", &KMedsWrapper::getMedoidsFinalPython)
+      .def_property_readonly("medoids", &KMedsWrapper::getMedoidsFinalPython)
       .def_property_readonly("build_medoids", &KMedsWrapper::getMedoidsBuildPython)
       .def_property_readonly("labels", &KMedsWrapper::getLabelsPython)
       .def_property_readonly("steps", &KMedsWrapper::getStepsPython)


Test patch:
diff --git a/tests/test_commit.py b/tests/test_commit.py
index 6cfbe433..990c61ee 100644
--- a/tests/test_commit.py
+++ b/tests/test_commit.py
@@ -15,7 +15,7 @@ def onFly(k, data, loss):
     kmed_bpam.fit(data, loss)
     kmed_naive.fit(data, loss)
 
-    if (kmed_bpam.final_medoids.tolist() == kmed_naive.final_medoids.tolist()) and \
+    if (kmed_bpam.medoids.tolist() == kmed_naive.medoids.tolist()) and \
        (kmed_bpam.build_medoids.tolist() == kmed_naive.build_medoids.tolist()):
         return 1
     else:
@@ -64,7 +64,7 @@ def test_small_cases_mnist(self):
         kmed_5.fit(self.small_mnist, "L2")
 
         self.assertEqual(kmed_5.build_medoids.tolist(), np.array([16, 32, 70, 87, 24]).tolist())
-        self.assertEqual(kmed_5.final_medoids.tolist(), np.array([30, 99, 70, 23, 49]).tolist())
+        self.assertEqual(kmed_5.medoids.tolist(), np.array([30, 99, 70, 23, 49]).tolist())
 
         kmed_10 = KMedoids(
             n_medoids = 10,
@@ -76,7 +76,7 @@ def test_small_cases_mnist(self):
         kmed_10.fit(self.small_mnist, "L2")
 
         self.assertEqual(kmed_10.build_medoids.tolist(), np.array([16, 32, 70, 87, 24, 90, 49, 99, 82, 94]).tolist())
-        self.assertEqual(kmed_10.final_medoids.tolist(), np.array([16, 63, 70, 25, 31, 90, 49, 99, 82, 94]).tolist())
+        self.assertEqual(kmed_10.medoids.tolist(), np.array([16, 63, 70, 25, 31, 90, 49, 99, 82, 94]).tolist())
 
     def test_small_cases_scrna(self):
         '''
@@ -92,7 +92,7 @@ def test_small_cases_scrna(self):
         kmed_5.fit(self.scrna.head(1000).to_numpy(), "L1")
 
         self.assertEqual(kmed_5.build_medoids.tolist(), np.array([377, 267, 276, 762, 394]).tolist())
-        self.assertEqual(kmed_5.final_medoids.tolist(), np.array([377, 267, 276, 762, 394]).tolist())
+        self.assertEqual(kmed_5.medoids.tolist(), np.array([377, 267, 276, 762, 394]).tolist())
 
         kmed_10 = KMedoids(
             n_medoids = 10,
@@ -104,7 +104,7 @@ def test_small_cases_scrna(self):
         kmed_10.fit(self.scrna.head(1000).to_numpy(), "L1")
 
         self.assertEqual(kmed_10.build_medoids.tolist(), np.array([377, 267, 276, 762, 394, 311, 663, 802, 422, 20]).tolist())
-        self.assertEqual(kmed_10.final_medoids.tolist(), np.array([377, 267, 276, 762, 394, 311, 663, 802, 422, 20]).tolist())
+        self.assertEqual(kmed_10.medoids.tolist(), np.array([377, 267, 276, 762, 394, 311, 663, 802, 422, 20]).tolist())
 
     def test_edge_cases(self):
         '''
@@ -113,7 +113,7 @@ def test_edge_cases(self):
         kmed = KMedoids()
 
         # initialized to empty
-        self.assertEqual([], kmed.final_medoids.tolist())
+        self.assertEqual([], kmed.medoids.tolist())
         self.assertEqual([], kmed.build_medoids.tolist())
 
         # error on trying to fit on empty
diff --git a/tests/test_push.py b/tests/test_push.py
index 4ef9fb76..5a1df3b5 100644
--- a/tests/test_push.py
+++ b/tests/test_push.py
@@ -15,7 +15,7 @@ def onFly(k, data, loss):
     kmed_bpam.fit(data, loss)
     kmed_naive.fit(data, loss)
 
-    if (kmed_bpam.final_medoids.tolist() == kmed_naive.final_medoids.tolist()) and \
+    if (kmed_bpam.medoids.tolist() == kmed_naive.medoids.tolist()) and \
        (kmed_bpam.build_medoids.tolist() == kmed_naive.build_medoids.tolist()):
         return 1
     else: