Skip to content

Commit

Permalink
update -> update_config
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Chigarev <[email protected]>
  • Loading branch information
dchigarev committed Apr 4, 2024
1 parent fa1c7f0 commit 3a57d4a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions docs/flow/modin/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ some config only for a certain part of the code:
print(cfg.RangePartitioning.get()) # False
# Set the config to 'True' inside of the context-manager
with cfg.update(cfg.RangePartitioning, True):
with cfg.update_config(cfg.RangePartitioning, True):
print(cfg.RangePartitioning.get()) # True
df.merge(...) # will use range-partitioning impl
# Once the context is over, the config gets back to its previous value
print(cfg.RangePartitioning.get()) # False
# You can also set multiple config at once when you pass a dictionary to 'cfg.update'
# You can also set multiple config at once when you pass a dictionary to 'cfg.update_config'
print(cfg.AsyncReadMode.get()) # False
with cfg.update({cfg.RangePartitioning: True, cfg.AsyncReadMode: True}):
with cfg.update_config({cfg.RangePartitioning: True, cfg.AsyncReadMode: True}):
print(cfg.RangePartitioning.get()) # True
print(cfg.AsyncReadMode.get()) # True
print(cfg.RangePartitioning.get()) # False
Expand Down
4 changes: 2 additions & 2 deletions modin/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@
TestReadFromSqlServer,
TrackFileLeaks,
)
from modin.config.pubsub import Parameter, ValueSource, update
from modin.config.pubsub import Parameter, ValueSource, update_config

__all__ = [
"EnvironmentVariable",
"Parameter",
"ValueSource",
"update",
"update_config",
# General settings
"IsDebug",
"Engine",
Expand Down
8 changes: 4 additions & 4 deletions modin/config/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ def add_option(cls, choice: Any) -> Any:


@contextlib.contextmanager
def update(
def update_config(
config: Union[Parameter, dict[Parameter, Any]], value: Any = lib.no_default
) -> Iterator[None]:
"""
Expand All @@ -475,14 +475,14 @@ def update(
... default = False
>>> MyParameter1.get()
False
>>> with update(MyParameter1, True):
>>> with update_config(MyParameter1, True):
... print(MyParameter1.get()) # True
True
>>> MyParameter1.get()
False
>>> class MyParameter2(Parameter, type=bool):
... default = True
>>> with update({MyParameter1: True, MyParameter2: False}):
>>> with update_config({MyParameter1: True, MyParameter2: False}):
... print(MyParameter1.get()) # True
... print(MyParameter2.get()) # False
True
Expand Down Expand Up @@ -510,4 +510,4 @@ def update(
cfg.put(val)


__all__ = ["Parameter", "update"]
__all__ = ["Parameter", "update_config"]
26 changes: 13 additions & 13 deletions modin/config/test/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import pytest

from modin.config import Parameter, update
from modin.config import Parameter, update_config
from modin.config.pubsub import ExactStr


Expand Down Expand Up @@ -104,22 +104,22 @@ def test_init_validation(vartype):
parameter.get()


def test_context_manager_update():
def test_context_manager_update_config():
parameter1 = make_prefilled(vartype=bool, varinit="False")

# simple case, 1 parameter
assert parameter1.get() is False
with update(parameter1, True):
with update_config(parameter1, True):
assert parameter1.get() is True
assert parameter1.get() is False

# nested case, 1 parameter
assert parameter1.get() is False
with update(parameter1, True):
with update_config(parameter1, True):
assert parameter1.get() is True
with update(parameter1, False):
with update_config(parameter1, False):
assert parameter1.get() is False
with update(parameter1, False):
with update_config(parameter1, False):
assert parameter1.get() is False
assert parameter1.get() is False
assert parameter1.get() is True
Expand All @@ -130,23 +130,23 @@ def test_context_manager_update():
# simple case, 2 parameters
assert parameter1.get() is False
assert parameter2.get() is True
with update({parameter1: True, parameter2: False}):
with update_config({parameter1: True, parameter2: False}):
assert parameter1.get() is True
assert parameter2.get() is False
assert parameter1.get() is False
assert parameter2.get() is True

# nested case, 2 parameters
with update({parameter1: True, parameter2: False}):
with update_config({parameter1: True, parameter2: False}):
assert parameter1.get() is True
assert parameter2.get() is False
with update(parameter1, False):
with update_config(parameter1, False):
assert parameter1.get() is False
assert parameter2.get() is False
with update(parameter2, True):
with update_config(parameter2, True):
assert parameter1.get() is False
assert parameter2.get() is True
with update({parameter1: True, parameter2: False}):
with update_config({parameter1: True, parameter2: False}):
assert parameter1.get() is True
assert parameter2.get() is False
assert parameter1.get() is False
Expand All @@ -162,11 +162,11 @@ def test_context_manager_update():
parameter3 = make_prefilled(vartype=ExactStr, varinit="42")

assert parameter3.get() == "42"
with update(parameter3, None):
with update_config(parameter3, None):
assert parameter3.get() is None
assert parameter3.get() == "42"

# test that raises if no value
with pytest.raises(ValueError):
with update(parameter3):
with update_config(parameter3):
pass

0 comments on commit 3a57d4a

Please sign in to comment.