Skip to content

Commit 83c2260

Browse files
committed
Necessary columns can be unordered
1 parent e2a7cb4 commit 83c2260

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Diff for: packages/python/plotly/plotly/express/_core.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1419,15 +1419,13 @@ def build_dataframe(args, constructor):
14191419
else:
14201420
# Save precious resources by only interchanging columns that are
14211421
# actually going to be plotted.
1422-
necessary_columns = [
1422+
necessary_columns = {
14231423
i for i in args.values() if isinstance(i, str) and i in columns
1424-
]
1424+
}
14251425
for field in args:
14261426
if args[field] is not None and field in array_attrables:
1427-
necessary_columns.extend(
1428-
[i for i in args[field] if i in columns]
1429-
)
1430-
columns = list(dict.fromkeys(necessary_columns))
1427+
necessary_columns.update(i for i in args[field] if i in columns)
1428+
columns = list(necessary_columns)
14311429
args["data_frame"] = pd.api.interchange.from_dataframe(
14321430
args["data_frame"].select_columns_by_name(columns)
14331431
)

Diff for: packages/python/plotly/plotly/tests/test_optional/test_px/test_px_input.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from plotly.express._core import build_dataframe
99
from pandas.testing import assert_frame_equal
1010

11+
1112
# Fixtures
1213
# --------
1314
@pytest.fixture
@@ -292,9 +293,10 @@ def __dataframe__(self):
292293
) as mock_from_dataframe:
293294
build_dataframe(args, go.Scatter)
294295
mock_from_dataframe.assert_called_once_with(interchange_dataframe_reduced)
295-
interchange_dataframe.select_columns_by_name.assert_called_with(
296-
["petal_width", "sepal_length"]
297-
)
296+
assert set(interchange_dataframe.select_columns_by_name.call_args.args[0]) == {
297+
"petal_width",
298+
"sepal_length",
299+
}
298300

299301
args = dict(data_frame=input_dataframe_reduced, color=None)
300302
with mock.patch(

0 commit comments

Comments
 (0)