Skip to content

Commit

Permalink
Copied row identifiers from arguments to results. Fixes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
vruusmann committed Jun 28, 2024
1 parent 3ab09e2 commit 3878664
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jpmml_evaluator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def evaluateAll(self, arguments_df, nan_as_missing = True):
except Exception as e:
raise self.backend.toJavaError(e)
results_dict = self.backend.loads(results)
results_df = DataFrame(data = results_dict["data"], columns = results_dict["columns"])
results_df = DataFrame(data = results_dict["data"], index = (arguments_df.index.copy() if (len(arguments_dict["data"]) == len(results_dict["data"])) else None), columns = results_dict["columns"])
if hasattr(self, "dropColumns"):
for dropColumn in self.dropColumns:
results_df.drop(str(dropColumn), axis = 1, inplace = True)
Expand Down
7 changes: 7 additions & 0 deletions jpmml_evaluator/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,19 @@ def workflow(self, backend, lax):
print(results_df.head(5))

self.assertEqual((150, 5), results_df.shape)
self.assertEqual(arguments_df.index.tolist(), results_df.index.tolist())
self.assertIsNot(arguments_df.index, results_df.index)

arguments_df.set_index(("row_{}".format(row + 1) for row in arguments_df.index.tolist()), inplace = True)

evaluator.suppressResultFields([reportOutputField])

results_df = evaluator.evaluateAll(arguments_df)

self.assertEqual((150, 4), results_df.shape)
self.assertEqual(arguments_df.index.tolist(), results_df.index.tolist())
self.assertEqual(["row_1", "row_2", "row_3"], results_df.index.tolist()[0:3])
self.assertIsNot(arguments_df.index, results_df.index)

expected_results_df = pandas.read_csv(_resource("DecisionTreeIris.csv"), sep = ",")

Expand Down

0 comments on commit 3878664

Please sign in to comment.