Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion narwhals/_arrow/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,14 @@ def collect(
raise AssertionError(msg) # pragma: no cover

def clone(self) -> Self:
return self._with_native(self.native, validate_column_names=False)
native = self.native
if self._backend_version < (14, 0, 0):
cloned_table = pa.table(
{col: pa.array(native.column(col)) for col in native.column_names}
Copy link
Member Author

@FBruzzesi FBruzzesi Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing:

Suggested change
{col: pa.array(native.column(col)) for col in native.column_names}
{col: native.column(col) for col in native.column_names}

triggers the type-checker 😩

Argument of type "dict[str, ChunkedArray[Any]]" cannot be assigned to parameter "data" of type "Collection[ArrayOrChunkedArray[Any]] | DataFrame | SupportArrowArray | SupportArrowStream | SupportArrowDeviceArray" in function "table"

)
else:
cloned_table = pa.table(native)
return self._with_native(cloned_table, validate_column_names=False)

def item(self, row: int | None, column: int | str | None) -> Any:
from narwhals._arrow.series import maybe_extract_py_scalar
Expand Down
1 change: 1 addition & 0 deletions tests/frame/clone_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def test_clone(constructor_eager: ConstructorEager) -> None:
df_clone = df.clone()
assert df is not df_clone
assert df._compliant_frame is not df_clone._compliant_frame
assert df.to_native() is not df_clone.to_native()
assert_equal_data(df_clone, expected)
df_clone_mod = df_clone.with_columns((nw.col("a") + nw.col("b")).alias("c"))
assert_equal_data(df, expected)
Expand Down
Loading