Skip to content

Commit

Permalink
Rename internal from_dataframe methods to from_interchange_dataframe
Browse files Browse the repository at this point in the history
Signed-off-by: sfc-gh-mvashishtha <[email protected]>
  • Loading branch information
sfc-gh-mvashishtha committed Jan 16, 2025
1 parent 0e57d6b commit fb6bba7
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion modin/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
Expand Down
2 changes: 1 addition & 1 deletion modin/core/dataframe/pandas/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions modin/core/execution/dispatching/factories/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions modin/core/execution/dispatching/factories/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions modin/core/io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()`.
Expand All @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions modin/core/storage_formats/base/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion modin/core/storage_formats/pandas/native_query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions modin/core/storage_formats/pandas/query_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
15 changes: 10 additions & 5 deletions modin/pandas/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
-------
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modin/tests/test_executions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_base_abstract_methods():
"from_pandas",
"from_arrow",
"default_to_pandas",
"from_dataframe",
"from_interchange_dataframe",
"to_interchange_dataframe",
]

Expand Down

0 comments on commit fb6bba7

Please sign in to comment.