internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: plotly/plotly.py

Issue:
[BUG]: sunburst/pie not using color_discrete_map argument
See https://stackoverflow.com/questions/60270054/how-can-i-set-the-colors-on-a-plotly-sunburst-chart


Discussion:
The problem also exists for pies:
```
import plotly.express as px
# This dataframe has 244 lines, but 4 distinct values for `day`
df = px.data.tips()
fig = px.pie(df, values='tip', names='day',
            color='day', 
                 color_discrete_map={'Sun':'blue', 
                                     'Sat':'red', 
                                     'Thur':'yellow', 
                                     'Fri':'green'})
fig.show()
```
![image](https://user-images.githubusercontent.com/263366/74751703-a4d21180-523b-11ea-9534-1133ba11f0c5.png)

Basically all charts where we accept discrete colors but we have one single trace.

Resolving patch:
diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py
--- a/packages/python/plotly/plotly/express/_core.py
+++ b/packages/python/plotly/plotly/express/_core.py
@@ -331,7 +331,10 @@ def make_trace_kwargs(args, trace_spec, trace_data, mapping_labels, sizeref):
                         mapping_labels[attr_label] = "%{color}"
                     else:
                         trace_patch["marker"]["colors"] = []
-                        mapping = {}
+                        if args["color_discrete_map"] is not None:
+                            mapping = args["color_discrete_map"].copy()
+                        else:
+                            mapping = {}
                         for cat in trace_data[attr_value]:
                             if mapping.get(cat) is None:
                                 mapping[cat] = args["color_discrete_sequence"][


Test patch:
diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py
--- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py
+++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_functions.py
@@ -218,6 +218,11 @@ def test_sunburst_treemap_with_path_color():
     fig = px.sunburst(df, path=path, color="vendors")
     assert len(np.unique(fig.data[0].marker.colors)) == 9
 
+    # Discrete color and color_discrete_map
+    cmap = {"Tech": "yellow", "Finance": "magenta", "(?)": "black"}
+    fig = px.sunburst(df, path=path, color="sectors", color_discrete_map=cmap)
+    assert np.all(np.in1d(fig.data[0].marker.colors, list(cmap.values())))
+
     # Numerical column in path
     df["regions"] = df["regions"].map({"North": 1, "South": 2})
     path = ["total", "regions", "sectors", "vendors"]
Repository: plotly/plotly.py

Issue:
default renderer not always automatically set
if I open ipython on my Ubuntu machine, I would like the default renderer to be set automatically to 'browser'  (as it's intended to be I think) but it's not the case:
```
$ ipython3
Python 3.7.3 (default, Oct  7 2019, 12:56:13) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.8.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import plotly.io as pio                                                                                                                          

In [2]: pio.renderers.default                                                                                                                            
Out[2]: 'plotly_mimetype+notebook'
```

With jupyter notebook and jupyter lab it works fine. @jonmmease is this intended to work? 


Discussion:

Resolving patch:
diff --git a/packages/python/plotly/plotly/io/_renderers.py b/packages/python/plotly/plotly/io/_renderers.py
--- a/packages/python/plotly/plotly/io/_renderers.py
+++ b/packages/python/plotly/plotly/io/_renderers.py
@@ -497,6 +497,12 @@ def show(fig, renderer=None, validate=True, **kwargs):
             # orca not found
             pass
 
+    # Check if we're running in ipython terminal
+    if not default_renderer and (
+        ipython.get_ipython().__class__.__name__ == "TerminalInteractiveShell"
+    ):
+        default_renderer = "browser"
+
     # Fallback to renderer combination that will work automatically
     # in the classic notebook (offline), jupyterlab, nteract, vscode, and
     # nbconvert HTML export.


Test patch:
Repository: plotly/plotly.py

Issue:
import plotly.graph_objects fails with ipywidget version is <= 7.0.0
Steps to reproduce:
<pre>
$ python3.7 -m venv test
$ . test/bin/activate
(test) $ pip install plotly
(test) $ pip install ipywidgets==6
(test) $ python -c "import plotly.graph_objects"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/varoquau/tmp/clean_venv/test/lib/python3.7/site-packages/plotly/graph_objects.py", line 2, in <module>
    from plotly.graph_objs import *
AttributeError: module 'plotly.graph_objs' has no attribute 'FigureWidget'
</pre>
The problem is on line 100184 of plotly/graph_objs/__init__.py: the `__all__.append("FigureWidget")` that is a few lines below should be moved under the "if" clause.

Given that it is generated code, I don't know how to fix it, so I won't send a pull request.


Discussion:
Indeed, we don’t support anything below 7.2.
Sorry, that’s actually 7.2 for classic Notebook and 7.5 for Jupyter Lab, according to our docs at https://plot.ly/python/getting-started/

Resolving patch:
diff --git a/packages/python/plotly/codegen/__init__.py b/packages/python/plotly/codegen/__init__.py
--- a/packages/python/plotly/codegen/__init__.py
+++ b/packages/python/plotly/codegen/__init__.py
@@ -259,9 +259,9 @@ def perform_codegen():
     from distutils.version import LooseVersion
     if LooseVersion(ipywidgets.__version__) >= LooseVersion('7.0.0'):
         from ._figurewidget import FigureWidget
+        __all__.append("FigureWidget")
     del LooseVersion
     del ipywidgets
-    __all__.append("FigureWidget")
 except ImportError:
     pass
 """
diff --git a/packages/python/plotly/plotly/graph_objs/__init__.py b/packages/python/plotly/plotly/graph_objs/__init__.py
--- a/packages/python/plotly/plotly/graph_objs/__init__.py
+++ b/packages/python/plotly/plotly/graph_objs/__init__.py
@@ -100182,8 +100182,9 @@ def __init__(
 
     if LooseVersion(ipywidgets.__version__) >= LooseVersion("7.0.0"):
         from ._figurewidget import FigureWidget
+
+        __all__.append("FigureWidget")
     del LooseVersion
     del ipywidgets
-    __all__.append("FigureWidget")
 except ImportError:
     pass


Test patch:
Repository: plotly/plotly.py

Issue:
Plotly Express density_mapbox, attribute 'opacity' raises ValueError
## Description
Hello,
When passing the `opacity` attribute different than `None` to `px.density_mapbox`, it raises a ValueError.

## Expected output
Taking the [example in the doc](https://plotly.com/python/mapbox-density-heatmaps/) and wanting to set the opacity to 0.5:
![image](https://user-images.githubusercontent.com/8888706/77640931-7a225980-6f5b-11ea-9471-7509bd430fa9.png)

## Minimal reproducible code
```python
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv')

import plotly.express as px
fig = px.density_mapbox(df, lat='Latitude', lon='Longitude', z='Magnitude', radius=10,
                        center=dict(lat=0, lon=180), zoom=0,
                        mapbox_style="stamen-terrain", opacity=0.5)
fig.show()
```

## Current workaround
It's possible to change the opacity by not adding the attribute in the constructor but adding it after using `fig.update_traces(opacity=0.5)`. But I'll open a PR with a fix so you don't have to use that.


Discussion:

Resolving patch:
diff --git a/packages/python/plotly/plotly/express/_chart_types.py b/packages/python/plotly/plotly/express/_chart_types.py
--- a/packages/python/plotly/plotly/express/_chart_types.py
+++ b/packages/python/plotly/plotly/express/_chart_types.py
@@ -1234,6 +1234,7 @@ def pie(
     template=None,
     width=None,
     height=None,
+    opacity=None,
     hole=None,
 ):
     """
@@ -1398,9 +1399,7 @@ def funnel(
     rectangular sector of a funnel.
     """
     return make_figure(
-        args=locals(),
-        constructor=go.Funnel,
-        trace_patch=dict(opacity=opacity, orientation=orientation),
+        args=locals(), constructor=go.Funnel, trace_patch=dict(orientation=orientation),
     )
 
 
@@ -1422,6 +1421,7 @@ def funnel_area(
     template=None,
     width=None,
     height=None,
+    opacity=None,
 ):
     """
     In a funnel area plot, each row of `data_frame` is represented as a
diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py
--- a/packages/python/plotly/plotly/express/_core.py
+++ b/packages/python/plotly/plotly/express/_core.py
@@ -1278,6 +1278,8 @@ def infer_config(args, constructor, trace_patch):
         if args["opacity"] is None:
             if "barmode" in args and args["barmode"] == "overlay":
                 trace_patch["marker"] = dict(opacity=0.5)
+        elif constructor in [go.Densitymapbox, go.Pie, go.Funnel, go.Funnelarea]:
+            trace_patch["opacity"] = args["opacity"]
         else:
             trace_patch["marker"] = dict(opacity=args["opacity"])
     if "line_group" in args:


Test patch:
Repository: plotly/plotly.py

Issue:
wide-mode type checking too strict
As reported in https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729/5?u=nicolaskruchten it would be nice if a mix of floats and ints were still accepted for wide-mode processing, rather than strictly saying the types don't match.


Discussion:

Resolving patch:
diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py
--- a/packages/python/plotly/plotly/express/_core.py
+++ b/packages/python/plotly/plotly/express/_core.py
@@ -1390,9 +1390,11 @@ def build_dataframe(args, constructor):
         del args["wide_cross"]
         dtype = None
         for v in wide_value_vars:
+            v_dtype = df_output[v].dtype.kind
+            v_dtype = "number" if v_dtype in ["i", "f", "u"] else v_dtype
             if dtype is None:
-                dtype = df_output[v].dtype
-            elif dtype != df_output[v].dtype:
+                dtype = v_dtype
+            elif dtype != v_dtype:
                 raise ValueError(
                     "Plotly Express cannot process wide-form data with columns of different type."
                 )


Test patch:
diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py
--- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py
+++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py
@@ -742,3 +742,9 @@ def test_mixed_input_error(df):
         "Plotly Express cannot process wide-form data with columns of different type"
         in str(err_msg.value)
     )
+
+
+def test_mixed_number_input():
+    df = pd.DataFrame(dict(a=[1, 2], b=[1.1, 2.1]))
+    fig = px.line(df)
+    assert len(fig.data) == 2
Repository: plotly/plotly.py

Issue:
in wide-mode, px.line should set line_group="variable"

_Originally posted by @nicolaskruchten in https://github.com/plotly/plotly.py/issues/2224#issuecomment-645052665_


Discussion:

Resolving patch:
diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py
--- a/packages/python/plotly/plotly/express/_core.py
+++ b/packages/python/plotly/plotly/express/_core.py
@@ -1422,6 +1422,8 @@ def build_dataframe(args, constructor):
             args["y" if orient_v else "x"] = value_name
             if constructor != go.Histogram2d:
                 args["color"] = args["color"] or var_name
+            if "line_group" in args:
+                args["line_group"] = args["line_group"] or var_name
         if constructor == go.Bar:
             if _is_continuous(df_output, value_name):
                 args["x" if orient_v else "y"] = wide_cross_name


Test patch:
diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py
--- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py
+++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px_wide.py
@@ -748,3 +748,20 @@ def test_mixed_number_input():
     df = pd.DataFrame(dict(a=[1, 2], b=[1.1, 2.1]))
     fig = px.line(df)
     assert len(fig.data) == 2
+
+
+def test_line_group():
+    df = pd.DataFrame(
+        data={
+            "who": ["a", "a", "b", "b"],
+            "x": [0, 1, 0, 1],
+            "score": [1.0, 2, 3, 4],
+            "miss": [3.2, 2.5, 1.3, 1.5],
+        }
+    )
+    fig = px.line(df, x="x", y=["miss", "score"])
+    assert len(fig.data) == 2
+    fig = px.line(df, x="x", y=["miss", "score"], color="who")
+    assert len(fig.data) == 4
+    fig = px.scatter(df, x="x", y=["miss", "score"], color="who")
+    assert len(fig.data) == 2
Repository: plotly/plotly.py

Issue:
px range_y should not impact marginals
![image](https://user-images.githubusercontent.com/203523/85327579-36c58180-b49d-11ea-944b-57d187011854.png)



Discussion:

Resolving patch:
diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py
--- a/packages/python/plotly/plotly/express/_core.py
+++ b/packages/python/plotly/plotly/express/_core.py
@@ -543,14 +543,18 @@ def configure_cartesian_marginal_axes(args, fig, orders):
 
     # Configure axis ticks on marginal subplots
     if args["marginal_x"]:
-        fig.update_yaxes(showticklabels=False, showline=False, ticks="", row=nrows)
+        fig.update_yaxes(
+            showticklabels=False, showline=False, ticks="", range=None, row=nrows
+        )
         if args["template"].layout.yaxis.showgrid is None:
             fig.update_yaxes(showgrid=args["marginal_x"] == "histogram", row=nrows)
         if args["template"].layout.xaxis.showgrid is None:
             fig.update_xaxes(showgrid=True, row=nrows)
 
     if args["marginal_y"]:
-        fig.update_xaxes(showticklabels=False, showline=False, ticks="", col=ncols)
+        fig.update_xaxes(
+            showticklabels=False, showline=False, ticks="", range=None, col=ncols
+        )
         if args["template"].layout.xaxis.showgrid is None:
             fig.update_xaxes(showgrid=args["marginal_y"] == "histogram", col=ncols)
         if args["template"].layout.yaxis.showgrid is None:


Test patch:
diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py
--- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py
+++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py
@@ -238,3 +238,18 @@ def test_permissive_defaults():
     msg = "'PxDefaults' object has no attribute 'should_not_work'"
     with pytest.raises(AttributeError, match=msg):
         px.defaults.should_not_work = "test"
+
+
+def test_marginal_ranges():
+    df = px.data.tips()
+    fig = px.scatter(
+        df,
+        x="total_bill",
+        y="tip",
+        marginal_x="histogram",
+        marginal_y="histogram",
+        range_x=[5, 10],
+        range_y=[5, 10],
+    )
+    assert fig.layout.xaxis2.range is None
+    assert fig.layout.yaxis3.range is None
Repository: plotly/plotly.py

Issue:
histogram() got an unexpected keyword argument 'legend' with pandas backend
pandas version 1.1.0
plotly version 4.9.0

The following will raise `histogram() got an unexpected keyword argument 'legend' `:
```python
import pandas as pd
pd.options.plotting.backend = "plotly"
df = pd.DataFrame()
df.hist()
```
I suggest to add `legend` in the skip list:
https://github.com/plotly/plotly.py/blob/dc9c5fdfe70367d5dc4fcdca6a0ad07125d64647/packages/python/plotly/plotly/__init__.py#L161


Discussion:

Resolving patch:
diff --git a/packages/python/plotly/plotly/__init__.py b/packages/python/plotly/plotly/__init__.py
--- a/packages/python/plotly/plotly/__init__.py
+++ b/packages/python/plotly/plotly/__init__.py
@@ -158,7 +158,7 @@ def hist_frame(data_frame, **kwargs):
     from .express import histogram
 
     skip = ["column", "by", "grid", "xlabelsize", "xrot", "ylabelsize", "yrot"]
-    skip += ["ax", "sharex", "sharey", "figsize", "layout", "bins"]
+    skip += ["ax", "sharex", "sharey", "figsize", "layout", "bins", "legend"]
     new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip}
     return histogram(data_frame, **new_kwargs)
 
@@ -172,6 +172,6 @@ def hist_series(data_frame, **kwargs):
     from .express import histogram
 
     skip = ["by", "grid", "xlabelsize", "xrot", "ylabelsize", "yrot", "ax"]
-    skip += ["figsize", "bins"]
+    skip += ["figsize", "bins", "legend"]
     new_kwargs = {k: kwargs[k] for k in kwargs if k not in skip}
     return histogram(data_frame, **new_kwargs)


Test patch:
Repository: plotly/plotly.py

Issue:
[v5.0.0rc2] Source tarball installation failed
@fcollonval question: I tried to `pip install <tarball>` and the labextension wasn't automatically installed. Is this by design/a known limitation?

_Originally posted by @nicolaskruchten in https://github.com/plotly/plotly.py/issues/3142#issuecomment-856117527_


Discussion:

Resolving patch:
diff --git a/packages/python/plotly/setup.py b/packages/python/plotly/setup.py
--- a/packages/python/plotly/setup.py
+++ b/packages/python/plotly/setup.py
@@ -33,6 +33,26 @@
     # Ensure the folder exists when we will look for files in it
     os.makedirs(labstatic)
 
+prebuilt_assets = [
+    (
+        "share/jupyter/labextensions/jupyterlab-plotly",
+        ["jupyterlab_plotly/labextension/package.json",],
+    ),
+    (
+        "share/jupyter/labextensions/jupyterlab-plotly/static",
+        [os.path.join(labstatic, f) for f in os.listdir(labstatic)],
+    ),
+    (
+        "share/jupyter/nbextensions/jupyterlab-plotly",
+        [
+            "jupyterlab_plotly/nbextension/extension.js",
+            "jupyterlab_plotly/nbextension/index.js",
+            "jupyterlab_plotly/nbextension/index.js.LICENSE.txt",
+        ],
+    ),
+]
+
+
 if "--skip-npm" in sys.argv or os.environ.get("SKIP_NPM") is not None:
     print("Skipping npm install as requested.")
     skip_npm = True
@@ -68,6 +88,7 @@ def run(self):
             if not is_repo and all(os.path.exists(t) for t in jsdeps.targets):
                 # sdist, nothing to do
                 command.run(self)
+                self.distribution.data_files.extend(prebuilt_assets)
                 return
 
             try:
@@ -94,26 +115,7 @@ def update_package_data(distribution):
 
     # JS assets will not be present if we are skip npm build
     if not skip_npm:
-        distribution.data_files.extend(
-            [
-                (
-                    "share/jupyter/labextensions/jupyterlab-plotly",
-                    ["jupyterlab_plotly/labextension/package.json",],
-                ),
-                (
-                    "share/jupyter/labextensions/jupyterlab-plotly/static",
-                    [os.path.join(labstatic, f) for f in os.listdir(labstatic)],
-                ),
-                (
-                    "share/jupyter/nbextensions/jupyterlab-plotly",
-                    [
-                        "jupyterlab_plotly/nbextension/extension.js",
-                        "jupyterlab_plotly/nbextension/index.js",
-                        "jupyterlab_plotly/nbextension/index.js.LICENSE.txt",
-                    ],
-                ),
-            ]
-        )
+        distribution.data_files.extend(prebuilt_assets)
 
     # re-init build_py options which load package_data
     build_py.finalize_options()


Test patch:
Repository: plotly/plotly.py

Issue:
Plotly Diagram file is non-deterministic due to random UUID
We use Plotly in conjunction with DVC, where DVC tracks the html file that Plotly generates as the output of one of our stages. DVC does some basic equality checking on the output files based on checksums. If a stage is run, and the Plotly-generated HTML changes its contents, we'll see that reflected in a different checksum in `dvc.lock`.

We found that Plotly will generate two different files, even if the input is identical. This is likely caused by this line, which is later emitted into the HTML:

https://github.com/plotly/plotly.py/blob/9a550187ad8a6ff9b84fa26a90cb0c1544a72eaa/packages/python/plotly/plotly/io/_html.py#L138

What are the reasons that lead to using a random ID? Could this potentially be some non-changing value?


Discussion:

Resolving patch:
diff --git a/packages/python/plotly/plotly/io/_html.py b/packages/python/plotly/plotly/io/_html.py
--- a/packages/python/plotly/plotly/io/_html.py
+++ b/packages/python/plotly/plotly/io/_html.py
@@ -38,6 +38,7 @@ def to_html(
     default_width="100%",
     default_height="100%",
     validate=True,
+    div_id=None,
 ):
     """
     Convert a figure to an HTML string representation.
@@ -135,7 +136,7 @@ def to_html(
     fig_dict = validate_coerce_fig_to_dict(fig, validate)
 
     # ## Generate div id ##
-    plotdivid = str(uuid.uuid4())
+    plotdivid = div_id or str(uuid.uuid4())
 
     # ## Serialize figure ##
     jdata = to_json_plotly(fig_dict.get("data", []))
@@ -391,6 +392,7 @@ def write_html(
     default_width="100%",
     default_height="100%",
     auto_open=False,
+    div_id=None,
 ):
     """
     Write a figure to an HTML file representation
@@ -512,6 +514,7 @@ def write_html(
         default_width=default_width,
         default_height=default_height,
         validate=validate,
+        div_id=div_id,
     )
 
     # Check if file is a string


Test patch:
diff --git a/packages/python/plotly/plotly/tests/test_io/test_html.py b/packages/python/plotly/plotly/tests/test_io/test_html.py
--- a/packages/python/plotly/plotly/tests/test_io/test_html.py
+++ b/packages/python/plotly/plotly/tests/test_io/test_html.py
@@ -38,3 +38,10 @@ def fig1(request):
 
 def test_versioned_cdn_included(fig1):
     assert plotly_cdn_url() in pio.to_html(fig1, include_plotlyjs="cdn")
+
+
+def test_html_deterministic(fig1):
+    div_id = "plotly-root"
+    assert pio.to_html(fig1, include_plotlyjs="cdn", div_id=div_id) == pio.to_html(
+        fig1, include_plotlyjs="cdn", div_id=div_id
+    )