|
3 | 3 | import json as _json |
4 | 4 | import sys |
5 | 5 | import re |
6 | | - |
7 | 6 | import pytz |
| 7 | +from _plotly_future_ import _future_flags |
8 | 8 |
|
9 | 9 | from _plotly_utils.optional_imports import get_module |
10 | 10 |
|
@@ -104,7 +104,9 @@ def default(self, obj): |
104 | 104 | self.encode_as_sage, |
105 | 105 | self.encode_as_numpy, |
106 | 106 | self.encode_as_pandas, |
107 | | - self.encode_as_datetime, |
| 107 | + (self.encode_as_datetime_v4 |
| 108 | + if 'timezones' in _future_flags |
| 109 | + else self.encode_as_datetime), |
108 | 110 | self.encode_as_date, |
109 | 111 | self.encode_as_list, # because some values have `tolist` do last. |
110 | 112 | self.encode_as_decimal |
@@ -170,6 +172,14 @@ def encode_as_numpy(obj): |
170 | 172 | else: |
171 | 173 | raise NotEncodable |
172 | 174 |
|
| 175 | + @staticmethod |
| 176 | + def encode_as_datetime_v4(obj): |
| 177 | + """Convert datetime objects to iso-format strings""" |
| 178 | + try: |
| 179 | + return obj.isoformat() |
| 180 | + except AttributeError: |
| 181 | + raise NotEncodable |
| 182 | + |
173 | 183 | @staticmethod |
174 | 184 | def encode_as_datetime(obj): |
175 | 185 | """Attempt to convert to utc-iso time string using datetime methods.""" |
|
0 commit comments