-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
accelerate plotly JSON encoder for numpy arrays without nans #2880
Changes from 7 commits
fcf2a5b
0fa810f
561edf1
8392ead
627c00f
c8e2922
224082e
5b18b2d
e528271
c46bae0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,15 @@ def encode(self, o): | |
Note that setting invalid separators will cause a failure at this step. | ||
|
||
""" | ||
|
||
# this will raise errors in a normal-expected way | ||
self.hasinfnans = False | ||
encoded_o = super(PlotlyJSONEncoder, self).encode(o) | ||
|
||
# Brute force guessing whether NaN or Infinity values are in the string | ||
# We catch false positive cases (e.g. strings such as titles, labels etc.) | ||
# but this is ok since the intention is to skip the decoding / reencoding | ||
# step when it's completely safe | ||
if not ("Infinity" in encoded_o or "NaN" in encoded_o): | ||
return encoded_o | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with this for now given your description of the performance characteristics. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe check for |
||
# now: | ||
# 1. `loads` to switch Infinity, -Infinity, NaN to None | ||
# 2. `dumps` again so you get 'null' instead of extended JSON | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you using
hasinfnans
anywhere else now?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no you were right :-). Thanks!