Skip to content

Commit cef56e2

Browse files
committed
fix: Avoid using iter_rows in _check_dataframe_all_leaves to enable cuDF input
1 parent 5898816 commit cef56e2

File tree

1 file changed

+16
-13
lines changed
  • packages/python/plotly/plotly/express

1 file changed

+16
-13
lines changed

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

+16-13
Original file line numberDiff line numberDiff line change
@@ -1858,17 +1858,20 @@ def _check_dataframe_all_leaves(df: nw.DataFrame) -> None:
18581858
null_mask=nw.any_horizontal(nw.all())
18591859
).get_column("null_mask")
18601860

1861-
for row_idx, row in zip(
1862-
null_indices_mask, null_mask.filter(null_indices_mask).iter_rows()
1863-
):
1864-
1865-
i = row.index(True)
1866-
1867-
if not all(row[i:]):
1868-
raise ValueError(
1869-
"None entries cannot have not-None children",
1870-
df_sorted.row(row_idx),
1861+
null_mask_filtered = null_mask.filter(null_indices_mask)
1862+
if not null_mask_filtered.is_empty():
1863+
for col_idx in range(1, null_mask_filtered.shape[1]):
1864+
# For each row, if a True value is encountered, then check that
1865+
# all values after that row are also True.
1866+
null_entries_with_non_null_children = (
1867+
~null_mask_filtered[:, col_idx] & null_mask_filtered[:, col_idx - 1]
18711868
)
1869+
if nw.to_py_scalar(null_entries_with_non_null_children.any()):
1870+
row_idx = null_entries_with_non_null_children.to_list().index(True)
1871+
raise ValueError(
1872+
"None entries cannot have not-None children",
1873+
df_sorted.row(row_idx),
1874+
)
18721875

18731876
fill_series = nw.new_series(
18741877
name="fill_value",
@@ -1893,13 +1896,13 @@ def _check_dataframe_all_leaves(df: nw.DataFrame) -> None:
18931896
)
18941897

18951898
null_indices = set(null_indices_mask.arg_true().to_list())
1896-
for i, (current_row, next_row) in enumerate(
1899+
for col_idx, (current_row, next_row) in enumerate(
18971900
zip(row_strings[:-1], row_strings[1:]), start=1
18981901
):
1899-
if (next_row in current_row) and (i in null_indices):
1902+
if (next_row in current_row) and (col_idx in null_indices):
19001903
raise ValueError(
19011904
"Non-leaves rows are not permitted in the dataframe \n",
1902-
df_sorted.row(i),
1905+
df_sorted.row(col_idx),
19031906
"is not a leaf.",
19041907
)
19051908

0 commit comments

Comments
 (0)