Skip to content

Commit a80c94a

Browse files
committed
add modifies_index flag
1 parent 749f177 commit a80c94a

File tree

7 files changed

+169
-20
lines changed

7 files changed

+169
-20
lines changed

narwhals/_dask/dataframe.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ def _from_native_frame(self, df: Any) -> Self:
4949
return self.__class__(df, backend_version=self._backend_version)
5050

5151
def with_columns(self, *exprs: DaskExpr, **named_exprs: DaskExpr) -> Self:
52+
n_modifies_index = sum(
53+
getattr(e, "_modifies_index", 0)
54+
for e in list(exprs) + list(named_exprs.values())
55+
)
56+
57+
if n_modifies_index > 0:
58+
msg = "Expressions that modify the index are not supported in `with_columns`."
59+
raise ValueError(msg)
60+
5261
new_series = parse_exprs_and_named_exprs(self, *exprs, **named_exprs)
5362
return self._from_native_frame(self._native_frame.assign(**new_series))
5463

@@ -101,6 +110,14 @@ def select(
101110
# This is a simple slice => fastpath!
102111
return self._from_native_frame(self._native_frame.loc[:, exprs])
103112

113+
n_modifies_index = sum(
114+
getattr(e, "_modifies_index", 0)
115+
for e in list(exprs) + list(named_exprs.values())
116+
)
117+
if n_modifies_index > 1:
118+
msg = "Found multiple expressions that modify the index"
119+
raise ValueError(msg)
120+
104121
new_series = parse_exprs_and_named_exprs(self, *exprs, **named_exprs)
105122

106123
if not new_series:

0 commit comments

Comments
 (0)