Skip to content

REF: Rename exchange -> interchange #47888

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 3 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/source/reference/general_functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ Importing from other DataFrame libraries
.. autosummary::
:toctree: api/

api.exchange.from_dataframe
api.interchange.from_dataframe
4 changes: 2 additions & 2 deletions pandas/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
""" public toolkit API """
from pandas.api import (
exchange,
extensions,
indexers,
interchange,
types,
)

__all__ = [
"exchange",
"interchange",
"extensions",
"indexers",
"types",
Expand Down
8 changes: 0 additions & 8 deletions pandas/api/exchange/__init__.py

This file was deleted.

8 changes: 8 additions & 0 deletions pandas/api/interchange/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Public API for DataFrame interchange protocol.
"""

from pandas.core.interchange.dataframe_protocol import DataFrame
from pandas.core.interchange.from_dataframe import from_dataframe

__all__ = ["from_dataframe", "DataFrame"]
10 changes: 5 additions & 5 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@

if TYPE_CHECKING:

from pandas.core.exchange.dataframe_protocol import DataFrame as DataFrameXchg
from pandas.core.groupby.generic import DataFrameGroupBy
from pandas.core.interchange.dataframe_protocol import DataFrame as DataFrameXchg
from pandas.core.internals import SingleDataManager
from pandas.core.resample import Resampler

Expand Down Expand Up @@ -819,7 +819,7 @@ def __dataframe__(
self, nan_as_null: bool = False, allow_copy: bool = True
) -> DataFrameXchg:
"""
Return the dataframe exchange object implementing the exchange protocol.
Return the dataframe interchange object implementing the interchange protocol.

Parameters
----------
Expand All @@ -832,19 +832,19 @@ def __dataframe__(

Returns
-------
DataFrame exchange object
DataFrame interchange object
The object which consuming library can use to ingress the dataframe.

Notes
-----
Details on the exchange protocol:
Details on the interchange protocol:
https://data-apis.org/dataframe-protocol/latest/index.html

`nan_as_null` currently has no effect; once support for nullable extension
dtypes is added, this value should be propagated to columns.
"""

from pandas.core.exchange.dataframe import PandasDataFrameXchg
from pandas.core.interchange.dataframe import PandasDataFrameXchg

return PandasDataFrameXchg(self, nan_as_null, allow_copy)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
from packaging import version

from pandas.core.exchange.dataframe_protocol import (
from pandas.core.interchange.dataframe_protocol import (
Buffer,
DlpackDeviceType,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
is_categorical_dtype,
is_string_dtype,
)
from pandas.core.exchange.buffer import PandasBuffer
from pandas.core.exchange.dataframe_protocol import (
from pandas.core.interchange.buffer import PandasBuffer
from pandas.core.interchange.dataframe_protocol import (
Column,
ColumnBuffers,
ColumnNullType,
DtypeKind,
)
from pandas.core.exchange.utils import (
from pandas.core.interchange.utils import (
ArrowCTypes,
Endianness,
NoBufferPresent,
Expand Down Expand Up @@ -136,7 +136,7 @@ def _dtype_from_pandasdtype(self, dtype) -> tuple[DtypeKind, int, str, str]:
kind = _NP_KINDS.get(dtype.kind, None)
if kind is None:
# Not a NumPy dtype. Check if it's a categorical maybe
raise ValueError(f"Data type {dtype} not supported by exchange protocol")
raise ValueError(f"Data type {dtype} not supported by interchange protocol")

return kind, dtype.itemsize * 8, dtype_to_arrow_c_fmt(dtype), dtype.byteorder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import TYPE_CHECKING

import pandas as pd
from pandas.core.exchange.column import PandasColumn
from pandas.core.exchange.dataframe_protocol import DataFrame as DataFrameXchg
from pandas.core.interchange.column import PandasColumn
from pandas.core.interchange.dataframe_protocol import DataFrame as DataFrameXchg

if TYPE_CHECKING:
from pandas import Index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class DataFrame(ABC):

@abstractmethod
def __dataframe__(self, nan_as_null: bool = False, allow_copy: bool = True):
"""Construct a new exchange object, potentially changing the parameters."""
"""Construct a new interchange object, potentially changing the parameters."""
pass

@property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import numpy as np

import pandas as pd
from pandas.core.exchange.dataframe_protocol import (
from pandas.core.interchange.dataframe_protocol import (
Buffer,
Column,
ColumnNullType,
DataFrame as DataFrameXchg,
DtypeKind,
)
from pandas.core.exchange.utils import (
from pandas.core.interchange.utils import (
ArrowCTypes,
Endianness,
)
Expand All @@ -34,7 +34,7 @@ def from_dataframe(df, allow_copy=True) -> pd.DataFrame:
Parameters
----------
df : DataFrameXchg
Object supporting the exchange protocol, i.e. `__dataframe__` method.
Object supporting the interchange protocol, i.e. `__dataframe__` method.
allow_copy : bool, default: True
Whether to allow copying the memory to perform the conversion
(if false then zero-copy approach is requested).
Expand All @@ -54,12 +54,12 @@ def from_dataframe(df, allow_copy=True) -> pd.DataFrame:

def _from_dataframe(df: DataFrameXchg, allow_copy=True):
"""
Build a ``pd.DataFrame`` from the DataFrame exchange object.
Build a ``pd.DataFrame`` from the DataFrame interchange object.

Parameters
----------
df : DataFrameXchg
Object supporting the exchange protocol, i.e. `__dataframe__` method.
Object supporting the interchange protocol, i.e. `__dataframe__` method.
allow_copy : bool, default: True
Whether to allow copying the memory to perform the conversion
(if false then zero-copy approach is requested).
Expand Down Expand Up @@ -91,7 +91,7 @@ def _from_dataframe(df: DataFrameXchg, allow_copy=True):

def protocol_df_chunk_to_pandas(df: DataFrameXchg) -> pd.DataFrame:
"""
Convert exchange protocol chunk to ``pd.DataFrame``.
Convert interchange protocol chunk to ``pd.DataFrame``.

Parameters
----------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Utility functions and objects for implementing the exchange API.
Utility functions and objects for implementing the interchange API.
"""

from __future__ import annotations
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test_np():


class TestApi(Base):
allowed = ["types", "extensions", "indexers", "exchange"]
allowed = ["types", "extensions", "indexers", "interchange"]

def test_api(self):
self.check(api, self.allowed)
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

import pandas as pd
import pandas._testing as tm
from pandas.core.exchange.dataframe_protocol import (
from pandas.core.interchange.dataframe_protocol import (
ColumnNullType,
DtypeKind,
)
from pandas.core.exchange.from_dataframe import from_dataframe
from pandas.core.interchange.from_dataframe import from_dataframe

test_data_categorical = {
"ordered": pd.Categorical(list("testdata") * 30, ordered=True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest

import pandas as pd
from pandas.core.exchange.utils import dtype_to_arrow_c_fmt
from pandas.core.interchange.utils import dtype_to_arrow_c_fmt

# TODO: use ArrowSchema to get reference C-string.
# At the time, there is no way to access ArrowSchema holding a type format string
Expand Down