-
Notifications
You must be signed in to change notification settings - Fork 136
fix: Preserve pandas column name attribute #2363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
feaad95
f28599f
fc982d3
f557dd5
46c29e7
d5fea77
f3b4cf9
9f3c415
bd7fd09
987a688
7f39ada
0d105a3
13166e7
afaa9ec
2cf041c
984a57b
823293b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -475,8 +475,8 @@ def _from_native_impl( # noqa: PLR0915 | |
return DataFrame( | ||
PandasLikeDataFrame( | ||
native_object, | ||
backend_version=parse_version(pd), | ||
implementation=Implementation.PANDAS, | ||
backend_version=parse_version(pd), | ||
Comment on lines
-478
to
+479
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mental sanity for symmetry with other pandas-like and order of the spec π |
||
version=version, | ||
validate_column_names=True, | ||
), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
import narwhals.stable.v1 as nw | ||
|
||
if TYPE_CHECKING: | ||
from tests.utils import Constructor | ||
|
||
|
||
def test_ops_preserve_column_index_name(constructor: Constructor) -> None: | ||
if not any(x in str(constructor) for x in ("pandas", "modin", "cudf", "dask")): | ||
pytest.skip( | ||
reason="Dataframe columns is a list and do not have a `name` like a pandas Index does" | ||
) | ||
|
||
data = {"a": [1, 3, 2], "b": [4, 4, 6], "z": [7.0, 8.0, 9.0]} | ||
df_native = constructor(data) | ||
df_native.columns.name = "foo" # type: ignore[union-attr] | ||
|
||
df = nw.from_native(df_native) | ||
|
||
result = df.with_columns(b=nw.col("a") + 1, c=nw.col("a") * 2).select("c", "b") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to concatenate two methods here, mostly for the sake of it. |
||
|
||
assert result.to_native().columns.name == "foo" # type: ignore[union-attr] | ||
assert result.lazy().collect(backend="pandas").to_native().columns.name == "foo" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dask
select
andwith_columns
have no issues since we use.assign
method for both!