Skip to content

Commit

Permalink
replace NaN values with None because the JSON encoder keeps the NaNs,…
Browse files Browse the repository at this point in the history
… which is illegal JSON.
  • Loading branch information
edeutsch committed Nov 1, 2024
1 parent 7f97614 commit 774076b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions code/ARAX/NodeSynonymizer/node_synonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import string
import sys
import time
import math
from collections import defaultdict, Counter
from typing import Optional, Union, List, Set, Dict, Tuple

Expand Down Expand Up @@ -403,6 +404,17 @@ def get_normalizer_results(self, entities: Optional[Union[str, Set[str], List[st
if normalizer_info:
normalizer_info["knowledge_graph"] = self._get_cluster_graph(normalizer_info)

# Attempt to squash NaNs, which are not legal in JSON. Turn them into nulls
if 'knowledge_graph' in normalizer_info and 'edges' in normalizer_info["knowledge_graph"]:
for edge_name, edge_data in normalizer_info["knowledge_graph"]['edges'].items():
if 'attributes' in edge_data:
for attribute in edge_data['attributes']:
try:
if 'value' in attribute and math.isnan(attribute['value']):
attribute['value'] = None
except:
pass

if debug:
print(f"Took {round(time.time() - start, 5)} seconds")
return results_dict
Expand Down

0 comments on commit 774076b

Please sign in to comment.