plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.38k stars 2.56k forks source link

add_vline fails in batch mode #4742

Open dejfh opened 3 months ago

dejfh commented 3 months ago

I am using plotly 5.24.0 with python 3.10.12 in a vs-code interactive window.

The following example raises TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str' in [...]/site-packages/plotly/basedatatypes.py:3995

import plotly.graph_objects as go

fig = go.Figure()

with fig.batch_update():
    fig.add_vline(1)

The same example without batch mode works fine:

import plotly.graph_objects as go

fig = go.Figure()

fig.add_vline(1)
sOnU1002 commented 2 months ago

Minimum Working Example (MWE): Here is a minimal example that reproduces the issue:

python Copy code import plotly.graph_objects as go

fig = go.Figure()

Raises TypeError when used in batch mode

with fig.batch_update(): fig.add_vline(1) When batch_update() is removed, the code works fine:

python Copy code import plotly.graph_objects as go

fig = go.Figure()

Works without batch mode

fig.add_vline(1) Expected Behavior: The add_vline() method should be compatible with the batch_update() context and should not raise any errors. The vertical line should be added while benefitting from the performance improvements of batch mode.

Actual Behavior: When the add_vline() method is called within batch_update(), a TypeError is raised, which appears to be related to appending a NoneType to a string at line 3995 in basedatatypes.py of Plotly's internal code.