Skip to content

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

Closed
@MarcoGorelli

Description

@MarcoGorelli

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions