Skip to content

Commit 76cc625

Browse files
committed
Don't drop timezones during serialization, just let Plotly.js ignore them
1 parent d7928b0 commit 76cc625

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

packages/python/plotly/plotly/io/_json.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,9 @@ def clean_to_json_compatible(obj, **kwargs):
496496
return np.ascontiguousarray(obj.values)
497497
elif obj.dtype.kind == "M":
498498
if isinstance(obj, pd.Series):
499-
dt_values = obj.dt.tz_localize(None).dt.to_pydatetime().tolist()
499+
dt_values = obj.dt.to_pydatetime().tolist()
500500
else: # DatetimeIndex
501-
dt_values = obj.tz_localize(None).to_pydatetime().tolist()
501+
dt_values = obj.to_pydatetime().tolist()
502502

503503
if not datetime_allowed:
504504
# Note: We don't need to handle dropping timezones here because
@@ -513,7 +513,6 @@ def clean_to_json_compatible(obj, **kwargs):
513513
try:
514514
# Need to drop timezone for scalar datetimes. Don't need to convert
515515
# to string since engine can do that
516-
obj = obj.replace(tzinfo=None)
517516
obj = obj.to_pydatetime()
518517
except (TypeError, AttributeError):
519518
pass

packages/python/plotly/plotly/tests/test_io/test_to_from_plotly_json.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def isoformat_test(dt_value):
3232
if isinstance(dt_value, np.datetime64):
3333
return str(dt_value)
3434
elif isinstance(dt_value, datetime.datetime):
35-
return dt_value.replace(tzinfo=None).isoformat()
35+
return dt_value.isoformat()
3636
else:
3737
raise ValueError("Unsupported date type: {}".format(type(dt_value)))
3838

@@ -181,18 +181,10 @@ def test_datetime(datetime_value, engine, pretty):
181181

182182

183183
def test_datetime_arrays(datetime_array, engine, pretty):
184-
if engine == "legacy":
185-
pytest.skip("legacy encoder doesn't strip timezone from datetimes arrays")
186-
187184
value = build_test_dict(datetime_array)
188185
result = pio.to_json_plotly(value, engine=engine)
189186

190187
def to_str(v):
191-
try:
192-
v = v.replace(tzinfo=None)
193-
except (TypeError, AttributeError):
194-
pass
195-
196188
try:
197189
v = v.isoformat(sep="T")
198190
except (TypeError, AttributeError):

0 commit comments

Comments
 (0)