diff --git a/_plotly_future_/timezones.py b/_plotly_future_/timezones.py new file mode 100644 index 00000000000..e6437b4a232 --- /dev/null +++ b/_plotly_future_/timezones.py @@ -0,0 +1,5 @@ +from __future__ import absolute_import +from _plotly_future_ import _future_flags, _assert_plotly_not_imported + +_assert_plotly_not_imported() +_future_flags.add('timezones') diff --git a/_plotly_future_/v4.py b/_plotly_future_/v4.py index ae38031e034..58cf0698ac6 100644 --- a/_plotly_future_/v4.py +++ b/_plotly_future_/v4.py @@ -6,6 +6,7 @@ remove_deprecations, v4_subplots, orca_defaults, + timezones, trace_uids, ) diff --git a/_plotly_utils/utils.py b/_plotly_utils/utils.py index 94d37a8b81b..10ae668946e 100644 --- a/_plotly_utils/utils.py +++ b/_plotly_utils/utils.py @@ -3,8 +3,8 @@ import json as _json import sys import re - import pytz +from _plotly_future_ import _future_flags from _plotly_utils.optional_imports import get_module @@ -104,7 +104,9 @@ def default(self, obj): self.encode_as_sage, self.encode_as_numpy, self.encode_as_pandas, - self.encode_as_datetime, + (self.encode_as_datetime_v4 + if 'timezones' in _future_flags + else self.encode_as_datetime), self.encode_as_date, self.encode_as_list, # because some values have `tolist` do last. self.encode_as_decimal @@ -170,6 +172,14 @@ def encode_as_numpy(obj): else: raise NotEncodable + @staticmethod + def encode_as_datetime_v4(obj): + """Convert datetime objects to iso-format strings""" + try: + return obj.isoformat() + except AttributeError: + raise NotEncodable + @staticmethod def encode_as_datetime(obj): """Attempt to convert to utc-iso time string using datetime methods."""