|
2 | 2 | import numpy as np
|
3 | 3 | import pandas as pd
|
4 | 4 | import pytest
|
5 |
| -import plotly.graph_objects as go |
6 |
| -import plotly |
7 | 5 | from plotly.express._core import build_dataframe
|
8 | 6 | from pandas.util.testing import assert_frame_equal
|
9 | 7 |
|
@@ -234,6 +232,24 @@ def test_build_df_with_index():
|
234 | 232 | assert_frame_equal(tips.reset_index()[out["data_frame"].columns], out["data_frame"])
|
235 | 233 |
|
236 | 234 |
|
| 235 | +def test_non_matching_index(): |
| 236 | + df = pd.DataFrame(dict(y=[1, 2, 3]), index=["a", "b", "c"]) |
| 237 | + |
| 238 | + expected = pd.DataFrame(dict(x=["a", "b", "c"], y=[1, 2, 3])) |
| 239 | + |
| 240 | + args = dict(data_frame=df, x=df.index, y="y") |
| 241 | + out = build_dataframe(args, all_attrables, array_attrables) |
| 242 | + assert_frame_equal(expected, out["data_frame"]) |
| 243 | + |
| 244 | + args = dict(data_frame=None, x=df.index, y=df.y) |
| 245 | + out = build_dataframe(args, all_attrables, array_attrables) |
| 246 | + assert_frame_equal(expected, out["data_frame"]) |
| 247 | + |
| 248 | + args = dict(data_frame=None, x=["a", "b", "c"], y=df.y) |
| 249 | + out = build_dataframe(args, all_attrables, array_attrables) |
| 250 | + assert_frame_equal(expected, out["data_frame"]) |
| 251 | + |
| 252 | + |
237 | 253 | def test_splom_case():
|
238 | 254 | iris = px.data.iris()
|
239 | 255 | fig = px.scatter_matrix(iris)
|
|
0 commit comments