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

FEAT-#4245: Define base interface for dataframe exchange protocol #4246

Merged
merged 16 commits into from
Feb 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ jobs:
- run: python -m pytest -n 2 modin/test/test_partition_api.py
- run: python -m pytest modin/test/test_utils.py
- run: python -m pytest asv_bench/test/test_utils.py
- run: python -m pytest modin/test/exchange/dataframe_protocol/base
- uses: codecov/codecov-action@v2

test-defaults:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- run: python -m pytest modin/test/storage_formats/pandas/test_internals.py
- run: python -m pytest modin/test/test_envvar_npartitions.py
- run: python -m pytest modin/test/test_partition_api.py
- run: python -m pytest modin/test/exchange/dataframe_protocol/base
- uses: codecov/codecov-action@v2

test-defaults:
Expand Down
2 changes: 1 addition & 1 deletion docs/release_notes/release_notes-0.14.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Key Features and Updates
* XGBoost enhancements
*
* Developer API enhancements
*
* FEAT-#4245: Define base interface for dataframe exchange protocol (#4246)
* Update testing suite
* TEST-#3628: Report coverage data for `test-internals` CI job (#4198)
* TEST-#3938: Test tutorial notebooks in CI (#4145)
Expand Down
47 changes: 47 additions & 0 deletions modin/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _saving_make_api_url(token, _make_api_url=modin.utils._make_api_url):
import modin # noqa: E402
import modin.config # noqa: E402
from modin.config import IsExperimental, TestRayClient # noqa: E402
import uuid # noqa: E402

from modin.core.storage_formats import ( # noqa: E402
PandasQueryCompiler,
Expand Down Expand Up @@ -233,6 +234,17 @@ def from_arrow(cls, at, data_cls):
def free(self):
pass

def to_dataframe(self, nan_as_null: bool = False, allow_copy: bool = True) -> dict:
raise NotImplementedError(
"The selected execution does not implement the DataFrame exchange protocol."
)

@classmethod
def from_dataframe(cls, df, data_cls):
raise NotImplementedError(
"The selected execution does not implement the DataFrame exchange protocol."
)

to_pandas = PandasQueryCompiler.to_pandas
default_to_pandas = PandasQueryCompiler.default_to_pandas

Expand All @@ -252,6 +264,41 @@ def set_base_execution(name=BASE_EXECUTION_NAME):
modin.set_execution(engine="python", storage_format=name.split("On")[0])


@pytest.fixture(scope="function")
def get_unique_base_execution():
"""Setup unique execution for a single function and yield its QueryCompiler that's suitable for inplace modifications."""
# It's better to use decimal IDs rather than hex ones due to factory names formatting
execution_id = int(uuid.uuid4().hex, 16)
format_name = f"Base{execution_id}"
engine_name = "Python"
execution_name = f"{format_name}On{engine_name}"

# Dynamically building all the required classes to form a new execution
base_qc = type(format_name, (TestQC,), {})
base_io = type(
f"{execution_name}IO", (BaseOnPythonIO,), {"query_compiler_cls": base_qc}
)
base_factory = type(
f"{execution_name}Factory",
(BaseOnPythonFactory,),
{"prepare": classmethod(lambda cls: setattr(cls, "io_cls", base_io))},
)

# Setting up the new execution
setattr(factories, f"{execution_name}Factory", base_factory)
old_engine, old_format = modin.set_execution(
engine=engine_name, storage_format=format_name
)
yield base_qc

# Teardown the new execution
modin.set_execution(engine=old_engine, storage_format=old_format)
try:
delattr(factories, f"{execution_name}Factory")
except AttributeError:
pass


def pytest_configure(config):
if config.option.extra_test_parameters is not None:
import modin.pandas.test.utils as utils
Expand Down
14 changes: 14 additions & 0 deletions modin/core/dataframe/base/exchange/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Licensed to Modin Development Team under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The Modin Development Team licenses this file to you under the
# Apache License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

"""Base Modin Dataframe functionality related to data exchange protocols."""
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Licensed to Modin Development Team under one or more contributor license agreements.
# See the NOTICE file distributed with this work for additional information regarding
# copyright ownership. The Modin Development Team licenses this file to you under the
# Apache License, Version 2.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

"""
Base Modin Dataframe functionality related to the dataframe exchange protocol.

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

from .dataframe import ProtocolDataframe

__all__ = ["ProtocolDataframe"]