Skip to content

Commit

Permalink
replace dot in float labels for mongoDB
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasplagwitz committed Sep 25, 2020
1 parent 5d38769 commit 4d8497d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions photonai/processing/photon_folds.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def data_overview(y):
return {}
else:
unique, counts = np.unique(y, return_counts=True)
unique = [str(u) for u in unique]
# replacing is necessary for float inputs, because mongoDB does not allow '.'-char
unique = [str(u).replace(".", "_") for u in unique]
counts = [int(c) for c in counts]
return dict(zip(unique, counts))

Expand Down Expand Up @@ -64,7 +65,7 @@ def generate_folds(cv_strategy, X, y, kwargs, eval_final_performance=True, test_
data_test_cases = cv_strategy.split(X, groups)
except:
logger.error("Could not stratify data for outer cross validation according to "
"group variable")
"group variable")
else:
data_test_cases = cv_strategy.split(X, y)

Expand Down
8 changes: 8 additions & 0 deletions test/processing_tests/test_results_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,11 @@ def test_get_performance_table(self):

def test_get_methods(self):
self.hyperpipe.results_handler.get_methods()

def test_float_labels_with_mongo(self):
"""
This test was added for a bug with float labels and saving to mongoDB.
"""
local_y = self.__y.astype(float)
self.hyperpipe.output_settings.mongodb_connect_url = self.mongodb_path
self.hyperpipe.fit(self.__X, local_y)

0 comments on commit 4d8497d

Please sign in to comment.