Skip to content

Commit 4cae985

Browse files
REFACTOR-#7418: Rename internal interchange protocol methods. (#7422)
Rename internal `to_dataframe` methods to `to_interchange_dataframe`, and internal `from_dataframe` methods to `from_interchange_dataframe`. Signed-off-by: sfc-gh-mvashishtha <[email protected]>
1 parent caa6116 commit 4cae985

File tree

12 files changed

+51
-29
lines changed

12 files changed

+51
-29
lines changed

modin/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,13 +183,15 @@ def from_arrow(cls, at, data_cls):
183183
def free(self):
184184
pass
185185

186-
def to_dataframe(self, nan_as_null: bool = False, allow_copy: bool = True):
186+
def to_interchange_dataframe(
187+
self, nan_as_null: bool = False, allow_copy: bool = True
188+
):
187189
raise NotImplementedError(
188190
"The selected execution does not implement the DataFrame exchange protocol."
189191
)
190192

191193
@classmethod
192-
def from_dataframe(cls, df, data_cls):
194+
def from_interchange_dataframe(cls, df, data_cls):
193195
raise NotImplementedError(
194196
"The selected execution does not implement the DataFrame exchange protocol."
195197
)

modin/core/dataframe/pandas/dataframe/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4807,7 +4807,7 @@ def __dataframe__(self, nan_as_null: bool = False, allow_copy: bool = True):
48074807
)
48084808

48094809
@classmethod
4810-
def from_dataframe(cls, df: ProtocolDataframe) -> PandasDataframe:
4810+
def from_interchange_dataframe(cls, df: ProtocolDataframe) -> PandasDataframe:
48114811
"""
48124812
Convert a DataFrame implementing the dataframe exchange protocol to a Core Modin Dataframe.
48134813

modin/core/execution/dispatching/factories/dispatcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ def from_non_pandas(cls, *args, **kwargs):
177177
return cls.get_factory()._from_non_pandas(*args, **kwargs)
178178

179179
@classmethod
180-
@_inherit_docstrings(factories.BaseFactory._from_dataframe)
181-
def from_dataframe(cls, *args, **kwargs):
182-
return cls.get_factory()._from_dataframe(*args, **kwargs)
180+
@_inherit_docstrings(factories.BaseFactory._from_interchange_dataframe)
181+
def from_interchange_dataframe(cls, *args, **kwargs):
182+
return cls.get_factory()._from_interchange_dataframe(*args, **kwargs)
183183

184184
@classmethod
185185
@_inherit_docstrings(factories.BaseFactory._from_ray)

modin/core/execution/dispatching/factories/factories.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ def _from_non_pandas(cls, *args, **kwargs):
200200
_doc_io_method_template,
201201
source="a DataFrame object supporting exchange protocol `__dataframe__()`",
202202
params=_doc_io_method_all_params,
203-
method="io.from_dataframe",
203+
method="io.from_interchange_dataframe",
204204
)
205-
def _from_dataframe(cls, *args, **kwargs):
206-
return cls.io_cls.from_dataframe(*args, **kwargs)
205+
def _from_interchange_dataframe(cls, *args, **kwargs):
206+
return cls.io_cls.from_interchange_dataframe(*args, **kwargs)
207207

208208
@classmethod
209209
@doc(

modin/core/io/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def from_arrow(cls, at):
100100
return cls.query_compiler_cls.from_arrow(at, cls.frame_cls)
101101

102102
@classmethod
103-
def from_dataframe(cls, df):
103+
def from_interchange_dataframe(cls, df):
104104
"""
105105
Create a Modin QueryCompiler from a DataFrame supporting the DataFrame exchange protocol `__dataframe__()`.
106106
@@ -114,7 +114,7 @@ def from_dataframe(cls, df):
114114
BaseQueryCompiler
115115
QueryCompiler containing data from the DataFrame.
116116
"""
117-
return cls.query_compiler_cls.from_dataframe(df, cls.frame_cls)
117+
return cls.query_compiler_cls.from_interchange_dataframe(df, cls.frame_cls)
118118

119119
@classmethod
120120
def from_ray(cls, ray_obj):

modin/core/storage_formats/base/query_compiler.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
StrDefault,
4646
StructDefault,
4747
)
48+
from modin.core.dataframe.base.interchange.dataframe_protocol.dataframe import (
49+
ProtocolDataframe,
50+
)
4851
from modin.error_message import ErrorMessage
4952
from modin.logging import ClassLogger
5053
from modin.logging.config import LogLevel
@@ -472,7 +475,9 @@ def to_numpy(self, **kwargs): # noqa: PR02
472475
# Dataframe exchange protocol
473476

474477
@abc.abstractmethod
475-
def to_dataframe(self, nan_as_null: bool = False, allow_copy: bool = True):
478+
def to_interchange_dataframe(
479+
self, nan_as_null: bool = False, allow_copy: bool = True
480+
) -> ProtocolDataframe:
476481
"""
477482
Get a DataFrame exchange protocol object representing data of the Modin DataFrame.
478483
@@ -501,13 +506,13 @@ def to_dataframe(self, nan_as_null: bool = False, allow_copy: bool = True):
501506

502507
@classmethod
503508
@abc.abstractmethod
504-
def from_dataframe(cls, df, data_cls):
509+
def from_interchange_dataframe(cls, df: ProtocolDataframe, data_cls):
505510
"""
506511
Build QueryCompiler from a DataFrame object supporting the dataframe exchange protocol `__dataframe__()`.
507512
508513
Parameters
509514
----------
510-
df : DataFrame
515+
df : ProtocolDataframe
511516
The DataFrame object supporting the dataframe exchange protocol.
512517
data_cls : type
513518
:py:class:`~modin.core.dataframe.pandas.dataframe.dataframe.PandasDataframe` class

modin/core/storage_formats/pandas/native_query_compiler.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
import pandas
2525
from pandas.core.dtypes.common import is_list_like, is_scalar
2626

27+
from modin.core.dataframe.base.interchange.dataframe_protocol.dataframe import (
28+
ProtocolDataframe,
29+
)
2730
from modin.core.storage_formats.base.query_compiler import BaseQueryCompiler
2831
from modin.core.storage_formats.pandas.query_compiler_caster import QueryCompilerCaster
2932
from modin.utils import (
@@ -1236,13 +1239,15 @@ def finalize(self):
12361239

12371240
# Dataframe exchange protocol
12381241

1239-
def to_dataframe(self, nan_as_null: bool = False, allow_copy: bool = True):
1242+
def to_interchange_dataframe(
1243+
self, nan_as_null: bool = False, allow_copy: bool = True
1244+
):
12401245
return self._modin_frame.__dataframe__(
12411246
nan_as_null=nan_as_null, allow_copy=allow_copy
12421247
)
12431248

12441249
@classmethod
1245-
def from_dataframe(cls, df, data_cls):
1250+
def from_interchange_dataframe(cls, df: ProtocolDataframe, data_cls):
12461251
return cls(pandas.api.interchange.from_dataframe(df))
12471252

12481253
# END Dataframe exchange protocol

modin/core/storage_formats/pandas/query_compiler.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
GroupByDefault,
6060
SeriesGroupByDefault,
6161
)
62+
from modin.core.dataframe.base.interchange.dataframe_protocol.dataframe import (
63+
ProtocolDataframe,
64+
)
6265
from modin.core.dataframe.pandas.metadata import (
6366
DtypesDescriptor,
6467
ModinDtypes,
@@ -381,14 +384,16 @@ def from_arrow(cls, at, data_cls):
381384

382385
# Dataframe exchange protocol
383386

384-
def to_dataframe(self, nan_as_null: bool = False, allow_copy: bool = True):
387+
def to_interchange_dataframe(
388+
self, nan_as_null: bool = False, allow_copy: bool = True
389+
):
385390
return self._modin_frame.__dataframe__(
386391
nan_as_null=nan_as_null, allow_copy=allow_copy
387392
)
388393

389394
@classmethod
390-
def from_dataframe(cls, df, data_cls):
391-
return cls(data_cls.from_dataframe(df))
395+
def from_interchange_dataframe(cls, df: ProtocolDataframe, data_cls):
396+
return cls(data_cls.from_interchange_dataframe(df))
392397

393398
# END Dataframe exchange protocol
394399

modin/pandas/dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2917,7 +2917,7 @@ def __dataframe__(self, nan_as_null: bool = False, allow_copy: bool = True):
29172917
ProtocolDataframe
29182918
A dataframe object following the dataframe protocol specification.
29192919
"""
2920-
return self._query_compiler.to_dataframe(
2920+
return self._query_compiler.to_interchange_dataframe(
29212921
nan_as_null=nan_as_null, allow_copy=allow_copy
29222922
)
29232923

modin/pandas/io.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
from pandas.io.parsers.readers import _c_parser_defaults
6666

6767
from modin.config import ModinNumpy
68+
from modin.core.dataframe.base.interchange.dataframe_protocol.dataframe import (
69+
ProtocolDataframe,
70+
)
6871
from modin.error_message import ErrorMessage
6972
from modin.logging import ClassLogger, enable_logging
7073
from modin.utils import (
@@ -1013,16 +1016,16 @@ def from_arrow(at) -> DataFrame:
10131016
return ModinObjects.DataFrame(query_compiler=FactoryDispatcher.from_arrow(at))
10141017

10151018

1016-
def from_dataframe(df) -> DataFrame:
1019+
def from_dataframe(df: ProtocolDataframe) -> DataFrame:
10171020
"""
1018-
Convert a DataFrame implementing the dataframe exchange protocol to a Modin DataFrame.
1021+
Convert a DataFrame implementing the dataframe interchange protocol to a Modin DataFrame.
10191022
10201023
See more about the protocol in https://data-apis.org/dataframe-protocol/latest/index.html.
10211024
10221025
Parameters
10231026
----------
1024-
df : DataFrame
1025-
The DataFrame object supporting the dataframe exchange protocol.
1027+
df : ProtocolDataframe
1028+
An object supporting the dataframe interchange protocol.
10261029
10271030
Returns
10281031
-------
@@ -1031,7 +1034,9 @@ def from_dataframe(df) -> DataFrame:
10311034
"""
10321035
from modin.core.execution.dispatching.factories.dispatcher import FactoryDispatcher
10331036

1034-
return ModinObjects.DataFrame(query_compiler=FactoryDispatcher.from_dataframe(df))
1037+
return ModinObjects.DataFrame(
1038+
query_compiler=FactoryDispatcher.from_interchange_dataframe(df)
1039+
)
10351040

10361041

10371042
def from_ray(ray_obj) -> DataFrame:

0 commit comments

Comments
 (0)