nadeemlab / SPT

Spatial profiling toolbox for spatial characterization of tumor immune microenvironment in multiplex images
https://oncopathtk.org
Other
21 stars 2 forks source link

Null data values conversion to JSON #218

Closed jimmymathews closed 1 year ago

jimmymathews commented 1 year ago

Occasionally the co-occurrence metric (and perhaps others) cannot be computed due to sparsity etc., in which case a nan value is sometimes returned. This should be None instead to support automatic conversion to JSON for return value to client applications.

ValueError: Out of range float values are not JSON compliant
CarlinLiao commented 1 year ago

I suspect this is coming from PendingProvider queries the quantitative_feature_value table. psycopg2 converts Python's float('nan') to SQL's NaN and float('inf') and float('-inf') are to Infinity and -Infinity for floating-point columns. When the values are pulled down and the float function applied to them, they all convert back to their respective float values. Catching these values and turning them into None when interpreting the SQL result ought to fix this issue.