From 0e8c2391d5b69c1d20607b1c9c697e0d54869e4c Mon Sep 17 00:00:00 2001 From: Alexander Ivanov Date: Thu, 19 Sep 2024 14:18:42 +0300 Subject: [PATCH] optimise select and with_columns --- narwhals/_pandas_like/dataframe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/narwhals/_pandas_like/dataframe.py b/narwhals/_pandas_like/dataframe.py index 17d05d3340..237cbf12b6 100644 --- a/narwhals/_pandas_like/dataframe.py +++ b/narwhals/_pandas_like/dataframe.py @@ -259,7 +259,7 @@ def select( ) -> Self: if exprs and all(isinstance(x, str) for x in exprs) and not named_exprs: # This is a simple slice => fastpath! - return self._from_native_frame(self._native_frame.loc[:, list(exprs)]) + return self._from_native_frame(self._native_frame[list(exprs)]) new_series = evaluate_into_exprs(self, *exprs, **named_exprs) if not new_series: # return empty dataframe, like Polars does @@ -349,7 +349,7 @@ def with_columns( ) ) else: - to_concat.append(self._native_frame.loc[:, name]) + to_concat.append(self._native_frame[name]) to_concat.extend( validate_dataframe_comparand(index, new_column_name_to_new_column_map[s]) for s in new_column_name_to_new_column_map