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

Interchange protocol: standardised way of getting back the native object #360

Open
MarcoGorelli opened this issue Oct 27, 2024 · 0 comments

Comments

@MarcoGorelli
Copy link
Contributor

If someone wants a standardised way of selecting columns 'a' and 'b' using the interchange protocol, then it would be nice to be able to do something like

df.__dataframe__().select_columns_by_name(['a', 'b']).to_native()

pandas and Polars both use ._df for this:

In [24]: pl.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7,8,9]}).__dataframe__().select_columns_by_name(['a', 'b'])._df
    ...:
Out[24]:
shape: (3, 2)
┌─────┬─────┐
│ ab   │
│ ------ │
│ i64i64 │
╞═════╪═════╡
│ 14   │
│ 25   │
│ 36   │
└─────┴─────┘

In [25]: pd.DataFrame({'a': [1,2,3], 'b': [4,5,6], 'c': [7,8,9]}).__dataframe__().select_columns_by_name(['a', 'b'])._df
    ...:
Out[25]:
   a  b
0  1  4
1  2  5
2  3  6

but that's not standardised by the interchange protocol

Use-case: the interchange level of support which we have in Narwhals: narwhals-dev/narwhals#1263

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant