Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 106269e

Browse files
Stop auto-converting timezones to UTC and stripping timezone info (#1581)
* Added timezones future flag * Don't convert datetimes to UTC or strip timezone info during JSON encoding
1 parent 870de12 commit 106269e

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

‎_plotly_future_/timezones.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from __future__ import absolute_import
2+
from _plotly_future_ import _future_flags, _assert_plotly_not_imported
3+
4+
_assert_plotly_not_imported()
5+
_future_flags.add('timezones')

‎_plotly_future_/v4.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
remove_deprecations,
77
v4_subplots,
88
orca_defaults,
9+
timezones,
910
trace_uids,
1011
)
1112

‎_plotly_utils/utils.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import json as _json
44
import sys
55
import re
6-
76
import pytz
7+
from _plotly_future_ import _future_flags
88

99
from _plotly_utils.optional_imports import get_module
1010

@@ -104,7 +104,9 @@ def default(self, obj):
104104
self.encode_as_sage,
105105
self.encode_as_numpy,
106106
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),
108110
self.encode_as_date,
109111
self.encode_as_list, # because some values have `tolist` do last.
110112
self.encode_as_decimal
@@ -170,6 +172,14 @@ def encode_as_numpy(obj):
170172
else:
171173
raise NotEncodable
172174

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+
173183
@staticmethod
174184
def encode_as_datetime(obj):
175185
"""Attempt to convert to utc-iso time string using datetime methods."""

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /