File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,21 @@ def sageJSONEncoder(self, obj):
126
126
pass
127
127
return None
128
128
129
+ def maskedNumbersEncoder (self , obj ):
130
+ """This catches masked numbers which can't be serialized.
131
+
132
+ Pandas (and others) may use masked numbers to signify data that's
133
+ not NaN, but also not valid in computations; something to be ignored.
134
+
135
+ """
136
+ import math
137
+ try :
138
+ if math .isnan (obj ):
139
+ return float ('NaN' )
140
+ except :
141
+ pass
142
+ return None
143
+
129
144
def builtinJSONEncoder (self , obj ):
130
145
try :
131
146
return obj .to_plotly_json ()
@@ -138,7 +153,7 @@ def default(self, obj):
138
153
except TypeError as e :
139
154
encoders = (self .builtinJSONEncoder , self .datetimeJSONEncoder ,
140
155
self .numpyJSONEncoder , self .pandasJSONEncoder ,
141
- self .sageJSONEncoder )
156
+ self .sageJSONEncoder , self . maskedNumbersEncoder )
142
157
for encoder in encoders :
143
158
s = encoder (obj )
144
159
if s is not None :
You can’t perform that action at this time.
0 commit comments