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

REFACTOR-#7418: Rename internal interchange protocol methods. #7422

Merged
Changes from 1 commit
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
Prev Previous commit
Rename internal from_dataframe methods to from_interchange_dataframe
Signed-off-by: sfc-gh-mvashishtha <mahesh.vashishtha@snowflake.com>
sfc-gh-mvashishtha committed Jan 16, 2025
commit fb6bba720e39d8490c477f670d2bc26c22e4641c
2 changes: 1 addition & 1 deletion modin/conftest.py
Original file line number Diff line number Diff line change
@@ -191,7 +191,7 @@ def to_interchange_dataframe(
)

@classmethod
def from_dataframe(cls, df, data_cls):
def from_interchange_dataframe(cls, df, data_cls):
raise NotImplementedError(
"The selected execution does not implement the DataFrame exchange protocol."
)
2 changes: 1 addition & 1 deletion modin/core/dataframe/pandas/dataframe/dataframe.py
Original file line number Diff line number Diff line change
@@ -4807,7 +4807,7 @@ def __dataframe__(self, nan_as_null: bool = False, allow_copy: bool = True):
)

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

6 changes: 3 additions & 3 deletions modin/core/execution/dispatching/factories/dispatcher.py
Original file line number Diff line number Diff line change
@@ -177,9 +177,9 @@ def from_non_pandas(cls, *args, **kwargs):
return cls.get_factory()._from_non_pandas(*args, **kwargs)

@classmethod
@_inherit_docstrings(factories.BaseFactory._from_dataframe)
def from_dataframe(cls, *args, **kwargs):
return cls.get_factory()._from_dataframe(*args, **kwargs)
@_inherit_docstrings(factories.BaseFactory._from_interchange_dataframe)
def from_interchange_dataframe(cls, *args, **kwargs):
return cls.get_factory()._from_interchange_dataframe(*args, **kwargs)

@classmethod
@_inherit_docstrings(factories.BaseFactory._from_ray)
6 changes: 3 additions & 3 deletions modin/core/execution/dispatching/factories/factories.py
Original file line number Diff line number Diff line change
@@ -200,10 +200,10 @@ def _from_non_pandas(cls, *args, **kwargs):
_doc_io_method_template,
source="a DataFrame object supporting exchange protocol `__dataframe__()`",
params=_doc_io_method_all_params,
method="io.from_dataframe",
method="io.from_interchange_dataframe",
)
def _from_dataframe(cls, *args, **kwargs):
return cls.io_cls.from_dataframe(*args, **kwargs)
def _from_interchange_dataframe(cls, *args, **kwargs):
return cls.io_cls.from_interchange_dataframe(*args, **kwargs)

@classmethod
@doc(
4 changes: 2 additions & 2 deletions modin/core/io/io.py
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ def from_arrow(cls, at):
return cls.query_compiler_cls.from_arrow(at, cls.frame_cls)

@classmethod
def from_dataframe(cls, df):
def from_interchange_dataframe(cls, df):
"""
Create a Modin QueryCompiler from a DataFrame supporting the DataFrame exchange protocol `__dataframe__()`.

@@ -114,7 +114,7 @@ def from_dataframe(cls, df):
BaseQueryCompiler
QueryCompiler containing data from the DataFrame.
"""
return cls.query_compiler_cls.from_dataframe(df, cls.frame_cls)
return cls.query_compiler_cls.from_interchange_dataframe(df, cls.frame_cls)

@classmethod
def from_ray(cls, ray_obj):
4 changes: 2 additions & 2 deletions modin/core/storage_formats/base/query_compiler.py
Original file line number Diff line number Diff line change
@@ -506,13 +506,13 @@ def to_interchange_dataframe(

@classmethod
@abc.abstractmethod
def from_dataframe(cls, df, data_cls):
def from_interchange_dataframe(cls, df: ProtocolDataframe, data_cls):
"""
Build QueryCompiler from a DataFrame object supporting the dataframe exchange protocol `__dataframe__()`.

Parameters
----------
df : DataFrame
df : ProtocolDataframe
The DataFrame object supporting the dataframe exchange protocol.
data_cls : type
:py:class:`~modin.core.dataframe.pandas.dataframe.dataframe.PandasDataframe` class
Original file line number Diff line number Diff line change
@@ -24,6 +24,9 @@
import pandas
from pandas.core.dtypes.common import is_list_like, is_scalar

from modin.core.dataframe.base.interchange.dataframe_protocol.dataframe import (
ProtocolDataframe,
)
from modin.core.storage_formats.base.query_compiler import BaseQueryCompiler
from modin.core.storage_formats.pandas.query_compiler_caster import QueryCompilerCaster
from modin.utils import (
@@ -1244,7 +1247,7 @@ def to_interchange_dataframe(
)

@classmethod
def from_dataframe(cls, df, data_cls):
def from_interchange_dataframe(cls, df: ProtocolDataframe, data_cls):
return cls(pandas.api.interchange.from_dataframe(df))

# END Dataframe exchange protocol
7 changes: 5 additions & 2 deletions modin/core/storage_formats/pandas/query_compiler.py
Original file line number Diff line number Diff line change
@@ -59,6 +59,9 @@
GroupByDefault,
SeriesGroupByDefault,
)
from modin.core.dataframe.base.interchange.dataframe_protocol.dataframe import (
ProtocolDataframe,
)
from modin.core.dataframe.pandas.metadata import (
DtypesDescriptor,
ModinDtypes,
@@ -389,8 +392,8 @@ def to_interchange_dataframe(
)

@classmethod
def from_dataframe(cls, df, data_cls):
return cls(data_cls.from_dataframe(df))
def from_interchange_dataframe(cls, df: ProtocolDataframe, data_cls):
return cls(data_cls.from_interchange_dataframe(df))

# END Dataframe exchange protocol

15 changes: 10 additions & 5 deletions modin/pandas/io.py
Original file line number Diff line number Diff line change
@@ -65,6 +65,9 @@
from pandas.io.parsers.readers import _c_parser_defaults

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


def from_dataframe(df) -> DataFrame:
def from_dataframe(df: ProtocolDataframe) -> DataFrame:
"""
Convert a DataFrame implementing the dataframe exchange protocol to a Modin DataFrame.
Convert a DataFrame implementing the dataframe interchange protocol to a Modin DataFrame.

See more about the protocol in https://data-apis.org/dataframe-protocol/latest/index.html.

Parameters
----------
df : DataFrame
The DataFrame object supporting the dataframe exchange protocol.
df : ProtocolDataframe
An object supporting the dataframe interchange protocol.

Returns
-------
@@ -1031,7 +1034,9 @@ def from_dataframe(df) -> DataFrame:
"""
from modin.core.execution.dispatching.factories.dispatcher import FactoryDispatcher

return ModinObjects.DataFrame(query_compiler=FactoryDispatcher.from_dataframe(df))
return ModinObjects.DataFrame(
query_compiler=FactoryDispatcher.from_interchange_dataframe(df)
)


def from_ray(ray_obj) -> DataFrame:
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ def dummy_io_method(*args, **kwargs):
raise TestPassed

query_compiler_cls = get_unique_base_execution
query_compiler_cls.from_dataframe = dummy_io_method
query_compiler_cls.from_interchange_dataframe = dummy_io_method
query_compiler_cls.to_interchange_dataframe = dummy_io_method

from modin.pandas.io import from_dataframe
2 changes: 1 addition & 1 deletion modin/tests/test_executions_api.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ def test_base_abstract_methods():
"from_pandas",
"from_arrow",
"default_to_pandas",
"from_dataframe",
"from_interchange_dataframe",
"to_interchange_dataframe",
]