Skip to content

Commit 8c55b05

Browse files
committed
fixup
1 parent 0d11047 commit 8c55b05

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

narwhals/dataframe.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,23 @@ def select(
143143
*exprs: IntoExpr | Iterable[IntoExpr],
144144
**named_exprs: IntoExpr,
145145
) -> Self:
146-
exprs = tuple(flatten(exprs))
147-
if exprs and all(isinstance(x, str) for x in exprs) and not named_exprs:
146+
flat_exprs = tuple(flatten(exprs))
147+
if flat_exprs and all(isinstance(x, str) for x in flat_exprs) and not named_exprs:
148148
# fast path!
149149
try:
150150
return self._from_compliant_dataframe(
151-
self._compliant_frame.simple_select(*exprs),
151+
self._compliant_frame.simple_select(*flat_exprs),
152152
)
153153
except Exception as e:
154154
# Column not found is the only thing that can realistically be raised here.
155-
msg = f"{e!s}\n\nHint: Did you mean one of these columns: {self.columns}?"
156-
raise ColumnNotFoundError(msg) from e
155+
available_columns = self.columns
156+
missing_columns = [x for x in flat_exprs if x not in available_columns]
157+
raise ColumnNotFoundError.from_missing_and_available_column_names(
158+
missing_columns, available_columns
159+
) from e
157160

158161
compliant_exprs, compliant_named_exprs = self._flatten_and_extract(
159-
*exprs, **named_exprs
162+
*flat_exprs, **named_exprs
160163
)
161164
return self._from_compliant_dataframe(
162165
self._compliant_frame.select(*compliant_exprs, **compliant_named_exprs),

0 commit comments

Comments
 (0)