Skip to content

Commit b2c332f

Browse files
committed
refactor: Rename as _concat_{ConcatMethod}
- More discoverable as related methods - Aligns a bit closer to https://github.com/pola-rs/polars/blob/ecfb7b5e09fd074ede5bd270453237d982495328/py-polars/polars/functions/eager.py#L241
1 parent 69f374e commit b2c332f

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

narwhals/_pandas_like/dataframe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ def select(self: PandasLikeDataFrame, *exprs: PandasLikeExpr) -> PandasLikeDataF
504504
return self._with_native(self.native.__class__(), validate_column_names=False)
505505
new_series = align_series_full_broadcast(*new_series)
506506
namespace = self.__narwhals_namespace__()
507-
df = namespace._horizontal_concat([s.native for s in new_series])
507+
df = namespace._concat_horizontal([s.native for s in new_series])
508508
return self._with_native(df, validate_column_names=True)
509509

510510
def drop_nulls(
@@ -527,7 +527,7 @@ def with_row_index(self: Self, name: str) -> Self:
527527
row_index = namespace._series.from_iterable(
528528
range(len(frame)), context=self, index=frame.index
529529
).alias(name)
530-
return self._with_native(namespace._horizontal_concat([row_index.native, frame]))
530+
return self._with_native(namespace._concat_horizontal([row_index.native, frame]))
531531

532532
def row(self: Self, index: int) -> tuple[Any, ...]:
533533
return tuple(x for x in self.native.iloc[index])
@@ -562,7 +562,7 @@ def with_columns(
562562
to_concat.append(series)
563563
to_concat.extend(self._extract_comparand(s) for s in name_columns.values())
564564
namespace = self.__narwhals_namespace__()
565-
df = namespace._horizontal_concat(to_concat)
565+
df = namespace._concat_horizontal(to_concat)
566566
return self._with_native(df, validate_column_names=False)
567567

568568
def rename(self: Self, mapping: Mapping[str, str]) -> Self:

narwhals/_pandas_like/group_by.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def agg(self: Self, *exprs: PandasLikeExpr) -> PandasLikeDataFrame: # noqa: PLR
233233
msg = f"Expected unique output names, got:{msg}"
234234
raise ValueError(msg)
235235
namespace = self.compliant.__narwhals_namespace__()
236-
result = namespace._horizontal_concat(result_aggs)
236+
result = namespace._concat_horizontal(result_aggs)
237237
else:
238238
# No aggregation provided
239239
result = self.compliant.__native_namespace__().DataFrame(

narwhals/_pandas_like/namespace.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,16 @@ def func(df: PandasLikeDataFrame) -> list[PandasLikeSeries]:
223223
context=self,
224224
)
225225

226-
def _horizontal_concat(self, dfs: Sequence[NDFrameT], /) -> NDFrameT:
226+
def _concat_diagonal(self, dfs: Sequence[NDFrameT], /) -> NDFrameT:
227+
"""Concatenate (native) DataFrames diagonally."""
228+
concat = self._implementation.to_native_namespace().concat
229+
if self._implementation.is_pandas() and self._backend_version < (3,):
230+
if self._backend_version < (1,):
231+
return concat(dfs, axis=0, copy=False, sort=False)
232+
return concat(dfs, axis=0, copy=False)
233+
return concat(dfs, axis=0)
234+
235+
def _concat_horizontal(self, dfs: Sequence[NDFrameT], /) -> NDFrameT:
227236
"""Concatenate (native) DataFrames horizontally."""
228237
concat = self._implementation.to_native_namespace().concat
229238
if self._implementation.is_cudf():
@@ -238,16 +247,7 @@ def _horizontal_concat(self, dfs: Sequence[NDFrameT], /) -> NDFrameT:
238247
return concat(dfs, axis=1, copy=False)
239248
return concat(dfs, axis=1)
240249

241-
def _diagonal_concat(self, dfs: Sequence[NDFrameT], /) -> NDFrameT:
242-
"""Concatenate (native) DataFrames diagonally."""
243-
concat = self._implementation.to_native_namespace().concat
244-
if self._implementation.is_pandas() and self._backend_version < (3,):
245-
if self._backend_version < (1,):
246-
return concat(dfs, axis=0, copy=False, sort=False)
247-
return concat(dfs, axis=0, copy=False)
248-
return concat(dfs, axis=0)
249-
250-
def _vertical_concat(self, dfs: Sequence[pd.DataFrame], /) -> pd.DataFrame:
250+
def _concat_vertical(self, dfs: Sequence[pd.DataFrame], /) -> pd.DataFrame:
251251
"""Concatenate (native) DataFrames vertically."""
252252
concat = self._implementation.to_native_namespace().concat
253253
cols_0 = dfs[0].columns
@@ -271,11 +271,11 @@ def concat(
271271
) -> PandasLikeDataFrame:
272272
dfs: list[pd.DataFrame] = [item.native for item in items]
273273
if how == "horizontal":
274-
native = self._horizontal_concat(dfs)
274+
native = self._concat_horizontal(dfs)
275275
elif how == "vertical":
276-
native = self._vertical_concat(dfs)
276+
native = self._concat_vertical(dfs)
277277
elif how == "diagonal":
278-
native = self._diagonal_concat(dfs)
278+
native = self._concat_diagonal(dfs)
279279
else:
280280
raise NotImplementedError
281281
return PandasLikeDataFrame.from_native(native, context=self)

0 commit comments

Comments
 (0)