Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 50847c9

Browse files
authored
PRED-2194 Use old reasonCodesPredictions route to support 4.3.x installs (#147)
* PRED-2194 use old reasonCodesPredictions route to support 4.3.x installs * ensure that deployment aware routes use predictionExplanations * cut official 1.15.3
1 parent c17ca96 commit 50847c9

File tree

5 files changed

+33
-7
lines changed

5 files changed

+33
-7
lines changed

CHANGES.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
1.15.3 (2019 Jan 7)
2+
===================
3+
4+
Bugfixes
5+
--------
6+
* Added support for ``--max_prediction_explanations`` on DataRobot 4.3.x .
7+
18
1.15.2 (2018 Dec 17)
29
=====================
310

@@ -17,7 +24,7 @@ Enhancements
1724

1825
Enhancements
1926
------------
20-
* Added new argument ``-max_prediction_explanations`` that allows batch scoring with predictions explanations and adds ``explanation_N_feature`` and ``explanation_N_strength`` to each row in output document (where ``N ∈ (1, max_prediction_explanations)`` )
27+
* Added new argument ``--max_prediction_explanations`` that allows batch scoring with predictions explanations and adds ``explanation_N_feature`` and ``explanation_N_strength`` to each row in output document (where ``N ∈ (1, max_prediction_explanations)`` )
2128

2229
1.14.2 (2018 Nov 14)
2330
====================
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.15.2'
1+
__version__ = '1.15.3'

datarobot_batch_scoring/api_response_handlers/pred_api_v10.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,24 @@ def format_data(result, batch, **opts):
7171
written_fields = out_fields[1:]
7272
comb = [row[1:] for row in pred]
7373

74-
if 'predictionExplanations' in single_row:
75-
num_reason_codes = len(single_row['predictionExplanations'])
74+
prediction_explanations_keys = ('predictionExplanations', 'reasonCodes',
75+
None)
76+
77+
def _find_prediction_explanations_key():
78+
return [key for key in prediction_explanations_keys
79+
if key in single_row or key is None][0]
80+
81+
prediction_explanations_key = _find_prediction_explanations_key()
82+
if prediction_explanations_key:
83+
num_reason_codes = len(single_row[prediction_explanations_key])
7684
for num in range(1, num_reason_codes + 1):
7785
written_fields += [
7886
'explanation_{0}_feature'.format(num),
7987
'explanation_{0}_strength'.format(num)
8088
]
8189
for in_row, out_row in zip(result, comb):
8290
reason_codes = []
83-
for raw_reason_code in in_row['predictionExplanations']:
91+
for raw_reason_code in in_row[prediction_explanations_key]:
8492
reason_codes += [
8593
raw_reason_code['feature'],
8694
raw_reason_code['strength']

datarobot_batch_scoring/batch_scoring.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,15 @@ def run_batch_predictions(base_url, base_headers, user, pwd,
133133
endpoint = base_url + '/'.join((pid, lid))
134134

135135
if max_prediction_explanations:
136-
endpoint += '/predictionExplanations?maxCodes=' + \
137-
str(max_prediction_explanations)
136+
if deployment_id is not None:
137+
# Deployment routes only support predictionExplanations.
138+
endpoint += '/predictionExplanations?maxCodes='
139+
else:
140+
# For non-deployment routes we use the old reasonCodesRoutes
141+
# to support 4.3.x releases.
142+
endpoint += '/reasonCodesPredictions?maxCodes='
143+
144+
endpoint += str(max_prediction_explanations)
138145
else:
139146
if deployment_id is not None:
140147
endpoint += '/predictions'

tests/liveserver_fixtures.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ def post_auth():
190190
@app.route('/predApi/v1.0/<pid>/<lid>/predict', methods=["POST"])
191191
@app.route('/predApi/v1.0/<pid>/<lid>/predictionExplanations',
192192
methods=["POST"])
193+
@app.route('/predApi/v1.0/<pid>/<lid>/reasonCodesPredictions',
194+
methods=["POST"])
193195
@app.route('/api/v1/<pid>/<lid>/predict', methods=["POST"])
194196
def predict_sinc(pid, lid):
195197
return _predict(lid)
@@ -205,6 +207,8 @@ def predict_deployment_aware(deployment_id):
205207
@app.route('/predApi/v1.0/<import_id>/predict', methods=["POST"])
206208
@app.route('/predApi/v1.0/<import_id>/predictionExplanations',
207209
methods=["POST"])
210+
@app.route('/predApi/v1.0/<import_id>/reasonCodesPredictions',
211+
methods=["POST"])
208212
@app.route('/api/v1/<import_id>/predict', methods=["POST"])
209213
def predict_transferable(import_id):
210214
return _predict(import_id)

0 commit comments

Comments
 (0)