From fb4a9449022bde322e7f17996e339638af40335e Mon Sep 17 00:00:00 2001 From: gerrymanoim Date: Thu, 9 Dec 2021 13:49:17 -0500 Subject: [PATCH] fix: restore the ability to have more than two option levels (#3151) * Restore the ability to have more than two option levels * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- ibis/config.py | 12 ++++-------- ibis/tests/test_api.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/ibis/config.py b/ibis/config.py index 214701f933ba..7d8c07f62620 100644 --- a/ibis/config.py +++ b/ibis/config.py @@ -570,14 +570,10 @@ def _get_root( tuple """ path = key.split('.') - if len(path) == 1: - return _global_config, path[0] - elif len(path) == 2: - return _global_config[path[0]], path[1] - else: - raise AssertionError( - f'Option keys cannot have more than 2 levels, found: {key}' - ) + cursor = _global_config + for p in path[:-1]: + cursor = cursor[p] + return (cursor, path[-1]) def _is_deprecated(key: str) -> bool: diff --git a/ibis/tests/test_api.py b/ibis/tests/test_api.py index 1fd94c1c3bea..237a2a68482a 100644 --- a/ibis/tests/test_api.py +++ b/ibis/tests/test_api.py @@ -130,3 +130,13 @@ def test_multiple_backends(mocker): msg = "3 packages found for backend 'foo'" with pytest.raises(RuntimeError, match=msg): ibis.foo + + +@pytest.mark.parametrize( + ('key', 'value'), [("two.levels", True), ("gt.two.levels", 55)] +) +def test_getting_setting_config_options(key, value): + ibis.config.register_option(key, "DEFAULT") + assert ibis.config.get_option(key) == "DEFAULT" + ibis.config.set_option(key, value) + assert ibis.config.get_option(key) == value