Skip to content

Commit

Permalink
perf: Impove pandas-backend indexing (#993)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Marco Gorelli <[email protected]>
  • Loading branch information
aivanoved and MarcoGorelli authored Oct 6, 2024
1 parent 8f2e834 commit a2ef4fe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions narwhals/_pandas_like/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def get_column(self, name: str) -> PandasLikeSeries:
from narwhals._pandas_like.series import PandasLikeSeries

return PandasLikeSeries(
self._native_frame.loc[:, name],
self._native_frame[name],
implementation=self._implementation,
backend_version=self._backend_version,
dtypes=self._dtypes,
Expand Down Expand Up @@ -157,7 +157,7 @@ def __getitem__(
from narwhals._pandas_like.series import PandasLikeSeries

return PandasLikeSeries(
self._native_frame.loc[:, item],
self._native_frame[item],
implementation=self._implementation,
backend_version=self._backend_version,
dtypes=self._dtypes,
Expand Down Expand Up @@ -276,7 +276,7 @@ def iter_rows(
@property
def schema(self) -> dict[str, DType]:
return {
col: native_to_narwhals_dtype(self._native_frame.loc[:, col], self._dtypes)
col: native_to_narwhals_dtype(self._native_frame[col], self._dtypes)
for col in self._native_frame.columns
}

Expand Down Expand Up @@ -382,7 +382,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
Expand Down Expand Up @@ -637,7 +637,7 @@ def to_dict(self, *, as_series: bool = False) -> dict[str, Any]:
# TODO(Unassigned): should this return narwhals series?
return {
col: PandasLikeSeries(
self._native_frame.loc[:, col],
self._native_frame[col],
implementation=self._implementation,
backend_version=self._backend_version,
dtypes=self._dtypes,
Expand Down
2 changes: 1 addition & 1 deletion narwhals/_pandas_like/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def from_column_names(
def func(df: PandasLikeDataFrame) -> list[PandasLikeSeries]:
return [
PandasLikeSeries(
df._native_frame.loc[:, column_name],
df._native_frame[column_name],
implementation=df._implementation,
backend_version=df._backend_version,
dtypes=df._dtypes,
Expand Down
2 changes: 1 addition & 1 deletion narwhals/_pandas_like/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def all(self) -> PandasLikeExpr:
return PandasLikeExpr(
lambda df: [
PandasLikeSeries(
df._native_frame.loc[:, column_name],
df._native_frame[column_name],
implementation=self._implementation,
backend_version=self._backend_version,
dtypes=self._dtypes,
Expand Down

0 comments on commit a2ef4fe

Please sign in to comment.