Skip to content

Commit

Permalink
FEAT-#6767: Implement 'modin.utils.enable_exp_mode' context manager
Browse files Browse the repository at this point in the history
Signed-off-by: Anatoly Myachev <[email protected]>
  • Loading branch information
anmyachev committed Nov 23, 2023
1 parent b8323b5 commit f5ba5a7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
9 changes: 7 additions & 2 deletions modin/core/execution/dispatching/factories/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class FactoryDispatcher(object):

__factory: factories.BaseFactory = None

@classmethod
def _reset_and_update_factory(cls):
if cls.__factory is None:
return
cls.__factory = cls._update_factory()

Check warning on line 113 in modin/core/execution/dispatching/factories/dispatcher.py

View check run for this annotation

Codecov / codecov/patch

modin/core/execution/dispatching/factories/dispatcher.py#L111-L113

Added lines #L111 - L113 were not covered by tests

@classmethod
def get_factory(cls) -> factories.BaseFactory:
"""Get current factory."""
Expand All @@ -118,8 +124,7 @@ def get_factory(cls) -> factories.BaseFactory:
return cls.__factory

@classmethod
# FIXME: replace `_` parameter with `*args`
def _update_factory(cls, _):
def _update_factory(cls, *args):
"""
Update and prepare factory with a new one specified via Modin config.
Expand Down
7 changes: 7 additions & 0 deletions modin/experimental/pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
to_pickle_distributed,
)


class ExpDataFrame(DataFrame): # noqa: F405
pass


DataFrame = ExpDataFrame

setattr(DataFrame, "to_pickle_distributed", to_pickle_distributed) # noqa: F405

warnings.warn(
Expand Down
15 changes: 15 additions & 0 deletions modin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Collection of general utility functions, mostly for internal use."""

import codecs
import contextlib
import functools
import importlib
import inspect
Expand Down Expand Up @@ -628,6 +629,20 @@ def execute(*objs: Iterable[Any], trigger_hdk_import: bool = False) -> None:
query_compiler.force_import()


@contextlib.contextmanager
def enable_exp_mode():
from modin.config import IsExperimental
from modin.core.execution.dispatching.factories.dispatcher import FactoryDispatcher

Check notice

Code scanning / CodeQL

Cyclic import Note

Import of module
modin.core.execution.dispatching.factories.dispatcher
begins an import cycle.

Check warning on line 635 in modin/utils.py

View check run for this annotation

Codecov / codecov/patch

modin/utils.py#L634-L635

Added lines #L634 - L635 were not covered by tests

old_value = IsExperimental.get()
IsExperimental.put(True)
FactoryDispatcher._reset_and_update_factory()
yield
IsExperimental.put(old_value or False)

Check warning on line 641 in modin/utils.py

View check run for this annotation

Codecov / codecov/patch

modin/utils.py#L637-L641

Added lines #L637 - L641 were not covered by tests
# cleanup potential side effects from importing `modin.experimental.pandas`
FactoryDispatcher._reset_and_update_factory()

Check warning on line 643 in modin/utils.py

View check run for this annotation

Codecov / codecov/patch

modin/utils.py#L643

Added line #L643 was not covered by tests


def wrap_into_list(*args: Any, skipna: bool = True) -> List[Any]:
"""
Wrap a sequence of passed values in a flattened list.
Expand Down

0 comments on commit f5ba5a7

Please sign in to comment.