-
Notifications
You must be signed in to change notification settings - Fork 653
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-#7141: Add an ability to use config variables with a context manager #7142
Conversation
…a context manager Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
modin/config/pubsub.py
Outdated
True | ||
""" | ||
if value is None: | ||
assert isinstance(config, dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asserts may be disabled in user code; it is better to throw ValueError
exception.
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
modin/config/pubsub.py
Outdated
True | ||
""" | ||
if value is not None: | ||
config = {cast(Parameter, config): value} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there (or could be in the future) any parameters that support None value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, it's better to use some nodefault
placeholder instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check isinstance(config, dict) first. The config parameter could be either dict or Parameter.
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
I've 2 minor suggestions:
with cfg.update(cfg.RangePartitioning, True):
...
with cfg.update({cfg.RangePartitioning: True, cfg.NPartitions: 1, cfg.MinPartitionSize: 64}):
... What about something like this? with cfg.context(RangePartitioning=True):
...
with cfg.context(RangePartitioning=True, NPartitions=1, MinPartitionSize=64):
... It seems more consistent and compact. # modin/config/__init__.py
modin_config = sys.modules[__name__]
@contextlib.contextmanager
def context(**configs):
for k, v in configs.items():
config = getattr(modin_config, k)
configs[k], _ = config.get(), config.put(v)
try:
yield
finally:
for k, v in configs.items():
getattr(modin_config, k).put(v) |
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
It looks good, but it limits even more on how users can apply this. For example, one must either use a string name to refer to a config or import it separately, they can't refer to a config using with cfg.context(cfg.RangePartitioning=True): # doesn't work
# File "<stdin>", line 1
# cfg.context(cfg.RangePartitioning=True)
# ^
# SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
# one should either do:
with cfg.context("RangePartitioning"=True):
...
# or import the config variable separately
from modin.config import RangePartitioning
with cfg.context(RangePartitioning=True):
... I don't like this type of limitation |
No, you don't need any additional imports. The code I provided works as is, the only import is required - |
import modin.config as config
with config.update_config(RangePartitioning=True):
... vs import modin.config as config
with config.context(RangePartitioning=True):
... vs import modin.config as config
with config.override(RangePartitioning=True):
... |
Agree, but it still doesn't allow you to write |
It doesn't, but do you really need it? |
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
>>> AsyncReadMode.get() | ||
False | ||
""" | ||
import modin.config as cfg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense moving this function to the modin.config module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean to modin/config/__ini__.py
? Idk whether we should define something without a strong reason in an __init__.py
file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but it's up to you. If you think the current location is better, I don't mind.
LGTM!
Signed-off-by: Dmitry Chigarev <dmitry.chigarev@intel.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! @AndreyPavlenko any more comments?
What do these changes do?
This PR enables for this behavior to be possible:
flake8 modin/ asv_bench/benchmarks scripts/doc_checker.py
black --check modin/ asv_bench/benchmarks scripts/doc_checker.py
git commit -s
docs/development/architecture.rst
is up-to-date