-
Notifications
You must be signed in to change notification settings - Fork 154
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
feaad95
concat
FBruzzesi f28599f
seems to work
FBruzzesi fc982d3
copy=False
FBruzzesi f557dd5
ok pandas 3
FBruzzesi 46c29e7
Merge branch 'main' into fix/maintain-pandas-column-index-name
FBruzzesi d5fea77
do not HACK non-pandas codepath
FBruzzesi f3b4cf9
mypy
FBruzzesi 9f3c415
Merge branch 'main' into fix/maintain-pandas-column-index-name
FBruzzesi bd7fd09
refactor: `utils.horizontal_concat` -> `Namespace._horizontal_concat`
dangotbanned 987a688
revert: undo last commit
dangotbanned 7f39ada
re-solve conflicts
FBruzzesi 0d105a3
re-solve conflicts
FBruzzesi 13166e7
fix pandas utils
FBruzzesi afaa9ec
Merge branch 'main' into fix/maintain-pandas-column-index-name
FBruzzesi 2cf041c
Merge branch 'main' into fix/maintain-pandas-column-index-name
FBruzzesi 984a57b
Merge branch 'main' into fix/maintain-pandas-column-index-name
FBruzzesi 823293b
Merge branch 'main' into fix/maintain-pandas-column-index-name
FBruzzesi 788bc1f
Merge branch 'main' into fix/maintain-pandas-column-index-name
FBruzzesi 1e745d4
merge main
FBruzzesi e1ef8b5
Merge branch 'main' into fix/maintain-pandas-column-index-name
FBruzzesi 28795f2
Merge remote-tracking branch 'upstream/main' into fix/maintain-pandasβ¦
MarcoGorelli 5efaff2
keep it simpler, dont trust pandas for rename_axis
MarcoGorelli f202c57
remove unintended file
MarcoGorelli e024c54
reduce diff
MarcoGorelli 5387649
reduce diff
MarcoGorelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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, request: pytest.FixtureRequest | ||
) -> 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" | ||
) | ||
if "dask" in str(constructor): | ||
# https://github.com/dask/dask/issues/11874 | ||
request.applymarker(pytest.mark.xfail) | ||
|
||
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") | ||
|
||
assert result.to_native().columns.name == "foo" # type: ignore[union-attr] | ||
assert result.lazy().collect(backend="pandas").to_native().columns.name == "foo" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I wanted to concatenate two methods here, mostly for the sake of it.
Might be worth reparametrizing it