Skip to content
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

bug: select and with_columns don't always preserve column index name for pandas-like #1483

Open
MarcoGorelli opened this issue Dec 2, 2024 · 2 comments

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Dec 2, 2024

import pandas as pd
# import narwhals.stable.v1 as nw
import narwhals as nw

df = pd.DataFrame({'a': [1,2,3], 'b': [4,5,6]})
df.columns.name = 'foo'

print(nw.from_native(df).select(c=nw.col('a')+1).to_native())
print(nw.from_native(df).with_columns(c=nw.col('a')+1).to_native())
print(nw.from_native(df).to_native())
print(nw.from_native(df).to_native().assign(c=lambda df: df['a']+1))

outputs

   c
0  2
1  3
2  4
   a  b  c
0  1  4  2
1  2  5  3
2  3  6  4
foo  a  b
0    1  4
1    2  5
2    3  6
foo  a  b  c
0    1  4  2
1    2  5  3
2    3  6  4

expected:

foo  c
0    2
1    3
2    4
foo  a  b  c
0    1  4  2
1    2  5  3
2    3  6  4
foo  a  b
0    1  4
1    2  5
2    3  6
foo  a  b  c
0    1  4  2
1    2  5  3
2    3  6  4
@MarcoGorelli
Copy link
Member Author

having said that...should we really care? is this in-scope for Narwhals? not totally sure I want to deal with multi-index columns' names weirdness

@FBruzzesi
Copy link
Member

should we really care?

I feel slightly uncomfortable not caring about it. Some "meta" information might be easy(er) than expected to preserve. Except at the same time I totally share this take:

not totally sure I want to deal with multi-index columns' names weirdness

and also:

is this in-scope for Narwhals?

Probably not 😂

thevro added a commit to thevro/narwhals that referenced this issue Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants