-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Add encoder to handle masked numbers. #159
Conversation
Yeah, great! I think instead of checking for |
…None Returning None for encoders failed in the case where the encodable value was actually None, like pd.NaT -> None
… datetime encoders
@chriddyp do we have tests to ensure that data isn't mutated when it goes through the encoder? Just making copies of all the things we're encoding and testing that they're the same after the tests? |
@@ -72,79 +73,115 @@ def ensure_dir_exists(directory): | |||
|
|||
|
|||
### Custom JSON encoders ### | |||
class NotEncodable(Exception): |
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.
let's subclass a PlotlyError here?
errr... maybe it doesn't matter cause we're catching it anyways... nbd
return None | ||
|
||
if isinstance(obj, (datetime.datetime, datetime.date)): | ||
if obj.microsecond != 0: |
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.
can you replace this with if obj.microsecond
?
o.strftime('%Y-%m-%d') | ||
for o in obj] | ||
else: | ||
raise NotEncodable |
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.
there's probably a more duck-typey way to do this. but it's not worth the time i think. i.e., just expecting attributes to exist etc...
@chriddyp is the 👨 |
Conflicts: plotly/version.py
🎉 nice! |
Add encoder to handle masked numbers.
@chriddyp , it'd be cool to get your input on this one, I think you wrote the encoders in here originally. I need to write a test before we pass this off still too.