aboutsummaryrefslogtreecommitdiff
path: root/gn3/api/correlation.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2021-12-30 10:21:46 +0300
committerFrederick Muriuki Muriithi2022-01-10 08:15:19 +0300
commit389fe9fee11760d8d046983bf27c82c019fd6d97 (patch)
treeb66d1a9c34165f7cc5f953e0d968c10e4afcf10e /gn3/api/correlation.py
parent032b259a3088402d90ca6d24bb987d5fb6ae1a57 (diff)
downloadgenenetwork3-389fe9fee11760d8d046983bf27c82c019fd6d97.tar.gz
Convert NaN to None
Issue: https://github.com/genenetwork/gn-gemtext-threads/blob/main/topics/gn1-migration-to-gn2/partial-correlations.gmi Comment: https://github.com/genenetwork/genenetwork3/pull/67#issuecomment-1000828159 * Convert NaN values to None to avoid possible bugs with the string replace method used before.
Diffstat (limited to 'gn3/api/correlation.py')
-rw-r--r--gn3/api/correlation.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/gn3/api/correlation.py b/gn3/api/correlation.py
index 1caf31f..b46855f 100644
--- a/gn3/api/correlation.py
+++ b/gn3/api/correlation.py
@@ -98,10 +98,10 @@ def partial_correlation():
Class to encode output into JSON, for objects which the default
json.JSONEncoder class does not have default encoding for.
"""
- def default(self, obj):
- if isinstance(obj, bytes):
- return str(obj, encoding="utf-8")
- return json.JSONEncoder.default(self, obj)
+ def default(self, o):
+ if isinstance(o, bytes):
+ return str(o, encoding="utf-8")
+ return json.JSONEncoder.default(self, o)
args = request.get_json()
conn, _cursor_object = database_connector()
@@ -110,7 +110,7 @@ def partial_correlation():
tuple(trait_fullname(trait) for trait in args["control_traits"]),
args["method"], int(args["criteria"]), args["target_db"])
response = make_response(
- json.dumps(corr_results, cls=OutputEncoder).replace(": NaN", ": null"),
+ json.dumps(corr_results, cls=OutputEncoder),
400 if "error" in corr_results.keys() else 200)
response.headers["Content-Type"] = "application/json"
return response