Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41ec4e8

Browse files
committed
Check for pandas objects that subclass datetimes in the datetime encoder
1 parent 75da4a3 commit 41ec4e8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

plotly/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import sys
1212
import threading
1313
import re
14+
import datetime
1415

1516
### incase people are using threading, we lock file reads
1617
lock = threading.Lock()
@@ -101,7 +102,14 @@ def datetimeJSONEncoder(self, obj):
101102
depending on what non-zero resolution was provided
102103
'''
103104
try:
105+
import pandas
106+
pandas_importable = True
104107
except:
108+
pandas_importable = False
109+
110+
if pandas_importable and obj is pandas.NaT:
111+
return None
112+
105113
if isinstance(obj, (datetime.datetime, datetime.date)):
106114
if obj.microsecond != 0:
107115
return obj.strftime('%Y-%m-%d %H:%M:%S.%f')

0 commit comments

Comments
 (0)