From 7acc583fddcdad0cc7d22e435a17a1ee49244784 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Fri, 1 Jul 2022 16:13:59 -0700 Subject: [PATCH 01/17] Config functions and importing to top level namespace --- python/cudf/cudf/__init__.py | 8 +++ python/cudf/cudf/config.py | 100 +++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 python/cudf/cudf/config.py diff --git a/python/cudf/cudf/__init__.py b/python/cudf/cudf/__init__.py index 373f5c5a86b..109d5379375 100644 --- a/python/cudf/cudf/__init__.py +++ b/python/cudf/cudf/__init__.py @@ -82,6 +82,14 @@ from cudf.utils.dtypes import _NA_REP from cudf.utils.utils import set_allocator +from .config import ( + register_config, + get_config, + set_config, + describe_config, + describe_configs, +) + try: from ptxcompiler.patch import patch_numba_codegen_if_needed except ImportError: diff --git a/python/cudf/cudf/config.py b/python/cudf/cudf/config.py new file mode 100644 index 00000000000..cf2ede009a1 --- /dev/null +++ b/python/cudf/cudf/config.py @@ -0,0 +1,100 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. + +from dataclasses import dataclass +from typing import Any, Callable, Dict + + +@dataclass +class CUDFConfiguration: + name: str + description: str + value: Any + validator: Callable + + +_CUDF_CONFIG: Dict[str, CUDFConfiguration] = {} + + +def register_config( + name: str, default_value: Any, description: str, validator: Callable +): + """Add a registry to the configuration dictionary. + + Parameters + ---------- + name : str + The name of the configuration. Also used as the key in the dictionary. + + default_value : Any + The default value of the configuration. + + description : str + A text description of the configuration. + + validator : Callable + A function that returns ``True`` is a given value is valid for the + configuration, ``False`` otherwise. + """ + if not validator(default_value): + raise ValueError(f"Invalid default value: {default_value}") + + _CUDF_CONFIG[name] = CUDFConfiguration( + name, default_value, description, validator + ) + + +def get_config(key: str) -> Any: + """Get the value of configuration. + + Parameters + ---------- + key : str + The name of the configuration. + + Returns + ------- + The value of the configuration. + """ + return _CUDF_CONFIG[key].value + + +def set_config(key: str, val: Any): + """Set the value of configuration. + + Raises ``ValueError`` if val is invalid to the configuration. + + Parameters + ---------- + key : str + The name of the configuration. + val : Any + The value to set. + """ + config = _CUDF_CONFIG[key] + if not config.validator(val): + raise ValueError(f"Invalid configuration {val}") + config.value = val + + +def describe_config(key: str) -> str: + """Returns the description of the configuration. + + Parameters + ---------- + key : str + The name of the configuration. + """ + return _CUDF_CONFIG[key].description + + +def describe_configs() -> Dict[str, str]: + """Returns all descriptions available in cudf. + + Returns + ------- + descriptions : Dict[str, str] + A dictionary mapping the name of the config to their descriptions. + """ + return { + config.name: config.description for config in _CUDF_CONFIG.values() + } From c25240c42307c341e787920409f2c3e8a57845b8 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Fri, 1 Jul 2022 16:15:16 -0700 Subject: [PATCH 02/17] Add config tests --- python/cudf/cudf/tests/test_config.py | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 python/cudf/cudf/tests/test_config.py diff --git a/python/cudf/cudf/tests/test_config.py b/python/cudf/cudf/tests/test_config.py new file mode 100644 index 00000000000..82940138a4b --- /dev/null +++ b/python/cudf/cudf/tests/test_config.py @@ -0,0 +1,48 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. + +import pytest + +import cudf + + +@pytest.fixture(scope="module") +def configuration_demo(): + cudf.register_config( + "odd_config", + 1, + "An odd configuration.", + lambda x: x % 2 == 1, + ) + yield + cudf.config._CUDF_CONFIG.pop("odd_config") + + +@pytest.fixture(scope="module") +def configuration_demo2(): + cudf.register_config( + "even_config", 0, "An even configuration.", lambda x: x % 2 == 0 + ) + yield + cudf.config._CUDF_CONFIG.pop("even_config") + + +def test_config_get_set(configuration_demo): + assert cudf.get_config("odd_config") == 1 + cudf.config.set_config("odd_config", 101) + assert cudf.get_config("odd_config") == 101 + + +def test_config_set_invalid(configuration_demo): + with pytest.raises(ValueError, match="Invalid configuration 0"): + cudf.set_config("odd_config", 0) + + +def test_config_description(configuration_demo): + assert cudf.describe_config("odd_config") == "An odd configuration." + + +def test_config_description_multi(configuration_demo, configuration_demo2): + assert cudf.describe_configs() == { + "odd_config": "An odd configuration.", + "even_config": "An even configuration.", + } From bfa10b6d40d6b11ab850430375fe29b4f0c44bde Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Fri, 1 Jul 2022 16:16:31 -0700 Subject: [PATCH 03/17] add documentation --- docs/cudf/source/api_docs/config.rst | 14 ++++++++++++++ docs/cudf/source/api_docs/index.rst | 1 + docs/cudf/source/developer_guide/config.md | 20 ++++++++++++++++++++ docs/cudf/source/developer_guide/index.md | 1 + docs/cudf/source/user_guide/config.md | 8 ++++++++ docs/cudf/source/user_guide/index.md | 1 + 6 files changed, 45 insertions(+) create mode 100644 docs/cudf/source/api_docs/config.rst create mode 100644 docs/cudf/source/developer_guide/config.md create mode 100644 docs/cudf/source/user_guide/config.md diff --git a/docs/cudf/source/api_docs/config.rst b/docs/cudf/source/api_docs/config.rst new file mode 100644 index 00000000000..936d6b19a66 --- /dev/null +++ b/docs/cudf/source/api_docs/config.rst @@ -0,0 +1,14 @@ +.. _api.config: + +============ +CUDF Configs +============ + +.. autosummary:: + :toctree: api/ + + cudf.register_config + cudf.get_config + cudf.set_config + cudf.describe_config + cudf.describe_configs diff --git a/docs/cudf/source/api_docs/index.rst b/docs/cudf/source/api_docs/index.rst index 87cb32fda36..8943bb9b12b 100644 --- a/docs/cudf/source/api_docs/index.rst +++ b/docs/cudf/source/api_docs/index.rst @@ -19,3 +19,4 @@ This page provides a list of all publicly accessible modules, methods and classe io subword_tokenize string_handling + config diff --git a/docs/cudf/source/developer_guide/config.md b/docs/cudf/source/developer_guide/config.md new file mode 100644 index 00000000000..931b16c19af --- /dev/null +++ b/docs/cudf/source/developer_guide/config.md @@ -0,0 +1,20 @@ +# CUDF Configuration + +Configurations are stored as a dictionary in `cudf.config` module. +Each configuration name is also its key in the dictionary. +The value of the configuration is an instance of a `CUDFConfiguration` object. + +A `CUDFConfiguration` object inherits from `dataclass` and consists 4 attributes: +- `name`: the name and the key of the configuration +- `value`: the current value of the configuration +- `description`: a text description of the configuration +- `validator`: a boolean function that returns `True` if value is valid, +`False` otherwise. + +Developers can use `cudf.register_config` to add configurations to the registry. +`cudf.get_config` is provided to get config value from the registry. + +When testing the behavior of certain configuration, +it is advised to use [yield fixture](https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#yield-fixtures-recommended) to setup and cleanup certain configuration for the test. + +See [API reference](api.config) for detail. diff --git a/docs/cudf/source/developer_guide/index.md b/docs/cudf/source/developer_guide/index.md index 61f30a45352..0db866cde77 100644 --- a/docs/cudf/source/developer_guide/index.md +++ b/docs/cudf/source/developer_guide/index.md @@ -4,3 +4,4 @@ :maxdepth: 2 library_design +config diff --git a/docs/cudf/source/user_guide/config.md b/docs/cudf/source/user_guide/config.md new file mode 100644 index 00000000000..9ea24260f3f --- /dev/null +++ b/docs/cudf/source/user_guide/config.md @@ -0,0 +1,8 @@ +# CUDF Configuration + +CUDF configurations are a set of key value pairs stored in a global dictionary. + +User may get the full list of cudf configurations with ``cudf.describe_configs``. +To set value to a configuration, use ``cudf.set_config``. + +See [API reference](api.config) for detail. diff --git a/docs/cudf/source/user_guide/index.md b/docs/cudf/source/user_guide/index.md index c1a63345df5..86098cecde6 100644 --- a/docs/cudf/source/user_guide/index.md +++ b/docs/cudf/source/user_guide/index.md @@ -12,5 +12,6 @@ groupby guide-to-udfs cupy-interop dask-cudf +config PandasCompat ``` From 68878cb9462d48c46217f03ddf6e9926691cd11e Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Wed, 13 Jul 2022 18:12:31 -0700 Subject: [PATCH 04/17] Update to `options` and conform to pandas API --- python/cudf/cudf/__init__.py | 10 +-- python/cudf/cudf/config.py | 100 ------------------------- python/cudf/cudf/options.py | 92 +++++++++++++++++++++++ python/cudf/cudf/tests/test_config.py | 48 ------------ python/cudf/cudf/tests/test_options.py | 48 ++++++++++++ 5 files changed, 144 insertions(+), 154 deletions(-) delete mode 100644 python/cudf/cudf/config.py create mode 100644 python/cudf/cudf/options.py delete mode 100644 python/cudf/cudf/tests/test_config.py create mode 100644 python/cudf/cudf/tests/test_options.py diff --git a/python/cudf/cudf/__init__.py b/python/cudf/cudf/__init__.py index 109d5379375..70471545ec0 100644 --- a/python/cudf/cudf/__init__.py +++ b/python/cudf/cudf/__init__.py @@ -82,12 +82,10 @@ from cudf.utils.dtypes import _NA_REP from cudf.utils.utils import set_allocator -from .config import ( - register_config, - get_config, - set_config, - describe_config, - describe_configs, +from .options import ( + get_option, + set_option, + describe_option, ) try: diff --git a/python/cudf/cudf/config.py b/python/cudf/cudf/config.py deleted file mode 100644 index cf2ede009a1..00000000000 --- a/python/cudf/cudf/config.py +++ /dev/null @@ -1,100 +0,0 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. - -from dataclasses import dataclass -from typing import Any, Callable, Dict - - -@dataclass -class CUDFConfiguration: - name: str - description: str - value: Any - validator: Callable - - -_CUDF_CONFIG: Dict[str, CUDFConfiguration] = {} - - -def register_config( - name: str, default_value: Any, description: str, validator: Callable -): - """Add a registry to the configuration dictionary. - - Parameters - ---------- - name : str - The name of the configuration. Also used as the key in the dictionary. - - default_value : Any - The default value of the configuration. - - description : str - A text description of the configuration. - - validator : Callable - A function that returns ``True`` is a given value is valid for the - configuration, ``False`` otherwise. - """ - if not validator(default_value): - raise ValueError(f"Invalid default value: {default_value}") - - _CUDF_CONFIG[name] = CUDFConfiguration( - name, default_value, description, validator - ) - - -def get_config(key: str) -> Any: - """Get the value of configuration. - - Parameters - ---------- - key : str - The name of the configuration. - - Returns - ------- - The value of the configuration. - """ - return _CUDF_CONFIG[key].value - - -def set_config(key: str, val: Any): - """Set the value of configuration. - - Raises ``ValueError`` if val is invalid to the configuration. - - Parameters - ---------- - key : str - The name of the configuration. - val : Any - The value to set. - """ - config = _CUDF_CONFIG[key] - if not config.validator(val): - raise ValueError(f"Invalid configuration {val}") - config.value = val - - -def describe_config(key: str) -> str: - """Returns the description of the configuration. - - Parameters - ---------- - key : str - The name of the configuration. - """ - return _CUDF_CONFIG[key].description - - -def describe_configs() -> Dict[str, str]: - """Returns all descriptions available in cudf. - - Returns - ------- - descriptions : Dict[str, str] - A dictionary mapping the name of the config to their descriptions. - """ - return { - config.name: config.description for config in _CUDF_CONFIG.values() - } diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py new file mode 100644 index 00000000000..18200c8f928 --- /dev/null +++ b/python/cudf/cudf/options.py @@ -0,0 +1,92 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. + +from dataclasses import dataclass +from typing import Any, Callable, Dict, Optional, Union + + +@dataclass +class CUDFOption: + value: Any + description: str + validator: Callable + + +_CUDF_OPTIONS: Dict[str, CUDFOption] = {} + + +def _register_option( + name: str, default_value: Any, description: str, validator: Callable +): + """Add a registry to the option dictionary. + + Parameters + ---------- + name : str + The name of the option. Also used as the key in the dictionary. + + default_value : Any + The default value of the option. + + description : str + A text description of the option. + + validator : Callable + A function that returns ``True`` is a given value is valid for the + option, ``False`` otherwise. + """ + if not validator(default_value): + raise ValueError(f"Invalid default value: {default_value}") + + _CUDF_OPTIONS[name] = CUDFOption(default_value, description, validator) + + +def get_option(key: str) -> Any: + """Get the value of option. + + Parameters + ---------- + key : str + The name of the option. + + Returns + ------- + The value of the option. + """ + return _CUDF_OPTIONS[key].value + + +def set_option(key: str, val: Any): + """Set the value of option. + + Raises ``ValueError`` if val is invalid to the option. + + Parameters + ---------- + key : str + The name of the option. + val : Any + The value to set. + """ + config = _CUDF_OPTIONS[key] + if not config.validator(val): + raise ValueError(f"Invalid option {val}") + config.value = val + + +def describe_option(key: Optional[str] = None) -> Union[str, Dict[str, str]]: + """Returns a specific option description or all option descriptions. + + Parameters + ---------- + key : str + The name of the option. + + Returns + ------- + A string description of the option or a dictionary of all option + descriptions. + """ + if key is None: + return {key: _CUDF_OPTIONS[key].description for key in _CUDF_OPTIONS} + + return _CUDF_OPTIONS[key].description diff --git a/python/cudf/cudf/tests/test_config.py b/python/cudf/cudf/tests/test_config.py deleted file mode 100644 index 82940138a4b..00000000000 --- a/python/cudf/cudf/tests/test_config.py +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) 2022, NVIDIA CORPORATION. - -import pytest - -import cudf - - -@pytest.fixture(scope="module") -def configuration_demo(): - cudf.register_config( - "odd_config", - 1, - "An odd configuration.", - lambda x: x % 2 == 1, - ) - yield - cudf.config._CUDF_CONFIG.pop("odd_config") - - -@pytest.fixture(scope="module") -def configuration_demo2(): - cudf.register_config( - "even_config", 0, "An even configuration.", lambda x: x % 2 == 0 - ) - yield - cudf.config._CUDF_CONFIG.pop("even_config") - - -def test_config_get_set(configuration_demo): - assert cudf.get_config("odd_config") == 1 - cudf.config.set_config("odd_config", 101) - assert cudf.get_config("odd_config") == 101 - - -def test_config_set_invalid(configuration_demo): - with pytest.raises(ValueError, match="Invalid configuration 0"): - cudf.set_config("odd_config", 0) - - -def test_config_description(configuration_demo): - assert cudf.describe_config("odd_config") == "An odd configuration." - - -def test_config_description_multi(configuration_demo, configuration_demo2): - assert cudf.describe_configs() == { - "odd_config": "An odd configuration.", - "even_config": "An even configuration.", - } diff --git a/python/cudf/cudf/tests/test_options.py b/python/cudf/cudf/tests/test_options.py new file mode 100644 index 00000000000..c1c4d0e580b --- /dev/null +++ b/python/cudf/cudf/tests/test_options.py @@ -0,0 +1,48 @@ +# Copyright (c) 2022, NVIDIA CORPORATION. + +import pytest + +import cudf + + +@pytest.fixture(scope="module") +def odd_option(): + cudf.options._register_option( + "odd_config", + 1, + "An odd option.", + lambda x: x % 2 == 1, + ) + yield + cudf.options._CUDF_OPTIONS.pop("odd_config") + + +@pytest.fixture(scope="module") +def even_option(): + cudf.options._register_option( + "even_config", 0, "An even option.", lambda x: x % 2 == 0 + ) + yield + cudf.options._CUDF_OPTIONS.pop("even_config") + + +def test_config_get_set(odd_option): + assert cudf.get_option("odd_config") == 1 + cudf.set_option("odd_config", 101) + assert cudf.get_option("odd_config") == 101 + + +def test_config_set_invalid(odd_option): + with pytest.raises(ValueError, match="Invalid option 0"): + cudf.set_option("odd_config", 0) + + +def test_config_description(odd_option): + assert cudf.describe_option("odd_config") == "An odd option." + + +def test_config_description_multi(odd_option, even_option): + assert cudf.describe_option() == { + "odd_config": "An odd option.", + "even_config": "An even option.", + } From e093eb6316f6ebe98f3856d97845127b73f0167a Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Wed, 13 Jul 2022 22:10:21 -0700 Subject: [PATCH 05/17] documentation updates --- docs/cudf/source/api_docs/config.rst | 14 ------------ docs/cudf/source/api_docs/index.rst | 2 +- docs/cudf/source/api_docs/options.rst | 12 +++++++++++ docs/cudf/source/developer_guide/config.md | 25 +++++++++++----------- python/cudf/cudf/options.py | 6 +++--- 5 files changed, 28 insertions(+), 31 deletions(-) delete mode 100644 docs/cudf/source/api_docs/config.rst create mode 100644 docs/cudf/source/api_docs/options.rst diff --git a/docs/cudf/source/api_docs/config.rst b/docs/cudf/source/api_docs/config.rst deleted file mode 100644 index 936d6b19a66..00000000000 --- a/docs/cudf/source/api_docs/config.rst +++ /dev/null @@ -1,14 +0,0 @@ -.. _api.config: - -============ -CUDF Configs -============ - -.. autosummary:: - :toctree: api/ - - cudf.register_config - cudf.get_config - cudf.set_config - cudf.describe_config - cudf.describe_configs diff --git a/docs/cudf/source/api_docs/index.rst b/docs/cudf/source/api_docs/index.rst index 8943bb9b12b..b77c98f3ac3 100644 --- a/docs/cudf/source/api_docs/index.rst +++ b/docs/cudf/source/api_docs/index.rst @@ -19,4 +19,4 @@ This page provides a list of all publicly accessible modules, methods and classe io subword_tokenize string_handling - config + options diff --git a/docs/cudf/source/api_docs/options.rst b/docs/cudf/source/api_docs/options.rst new file mode 100644 index 00000000000..28143eaaf2d --- /dev/null +++ b/docs/cudf/source/api_docs/options.rst @@ -0,0 +1,12 @@ +.. _api.options: + +============ +cudf Options +============ + +.. autosummary:: + :toctree: api/ + + cudf.get_option + cudf.set_option + cudf.describe_option diff --git a/docs/cudf/source/developer_guide/config.md b/docs/cudf/source/developer_guide/config.md index 931b16c19af..a0840626fc4 100644 --- a/docs/cudf/source/developer_guide/config.md +++ b/docs/cudf/source/developer_guide/config.md @@ -1,20 +1,19 @@ -# CUDF Configuration +# Options -Configurations are stored as a dictionary in `cudf.config` module. -Each configuration name is also its key in the dictionary. -The value of the configuration is an instance of a `CUDFConfiguration` object. +Options are stored as a dictionary in `cudf.options` module. +Each option name is also its key in the dictionary. +The value of the option is an instance of a `CUDFOption` object. -A `CUDFConfiguration` object inherits from `dataclass` and consists 4 attributes: -- `name`: the name and the key of the configuration -- `value`: the current value of the configuration -- `description`: a text description of the configuration +A `CUDFOption` object has the following attributes: +- `value`: the current value of the option +- `description`: a text description of the option - `validator`: a boolean function that returns `True` if value is valid, `False` otherwise. -Developers can use `cudf.register_config` to add configurations to the registry. -`cudf.get_config` is provided to get config value from the registry. +Developers can use `cudf.options._register_option` to add options to the dictionary. +`cudf.get_option` is provided to get config value from the dictionary. -When testing the behavior of certain configuration, -it is advised to use [yield fixture](https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#yield-fixtures-recommended) to setup and cleanup certain configuration for the test. +When testing the behavior of a certain option, +it is advised to use [yield fixture](https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#yield-fixtures-recommended) to setup and cleanup the option. -See [API reference](api.config) for detail. +See [API reference](api.options) for detail. diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index 18200c8f928..0fb46ec699c 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -17,7 +17,7 @@ class CUDFOption: def _register_option( name: str, default_value: Any, description: str, validator: Callable ): - """Add a registry to the option dictionary. + """Register an entry in the option dictionary. Parameters ---------- @@ -31,7 +31,7 @@ def _register_option( A text description of the option. validator : Callable - A function that returns ``True`` is a given value is valid for the + A function that returns ``True`` if a given value is valid for the option, ``False`` otherwise. """ if not validator(default_value): @@ -58,7 +58,7 @@ def get_option(key: str) -> Any: def set_option(key: str, val: Any): """Set the value of option. - Raises ``ValueError`` if val is invalid to the option. + Raises ``ValueError`` if the provided value is invalid. Parameters ---------- From bbd9cd42977d39b5717e0a8f09b57165d25e9968 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Wed, 13 Jul 2022 22:11:41 -0700 Subject: [PATCH 06/17] More docs update --- docs/cudf/source/user_guide/config.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/cudf/source/user_guide/config.md b/docs/cudf/source/user_guide/config.md index 9ea24260f3f..2a1063410c2 100644 --- a/docs/cudf/source/user_guide/config.md +++ b/docs/cudf/source/user_guide/config.md @@ -1,8 +1,8 @@ -# CUDF Configuration +# Options -CUDF configurations are a set of key value pairs stored in a global dictionary. +CUDF options are a set of key value pairs stored in a global dictionary. -User may get the full list of cudf configurations with ``cudf.describe_configs``. -To set value to a configuration, use ``cudf.set_config``. +User may get the full list of cudf options with ``cudf.describe_option``. +To set value to a option, use ``cudf.set_option``. -See [API reference](api.config) for detail. +See [API reference](api.options) for detail. From 90cbe334b60b9c2108d66af5e2435caa75902b50 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Mon, 18 Jul 2022 14:05:25 -0700 Subject: [PATCH 07/17] Docs update --- docs/cudf/source/developer_guide/index.md | 2 +- .../source/developer_guide/{config.md => options.md} | 0 docs/cudf/source/user_guide/config.md | 8 -------- docs/cudf/source/user_guide/index.md | 2 +- docs/cudf/source/user_guide/options.md | 9 +++++++++ 5 files changed, 11 insertions(+), 10 deletions(-) rename docs/cudf/source/developer_guide/{config.md => options.md} (100%) delete mode 100644 docs/cudf/source/user_guide/config.md create mode 100644 docs/cudf/source/user_guide/options.md diff --git a/docs/cudf/source/developer_guide/index.md b/docs/cudf/source/developer_guide/index.md index 0db866cde77..f37508c13d6 100644 --- a/docs/cudf/source/developer_guide/index.md +++ b/docs/cudf/source/developer_guide/index.md @@ -4,4 +4,4 @@ :maxdepth: 2 library_design -config +options diff --git a/docs/cudf/source/developer_guide/config.md b/docs/cudf/source/developer_guide/options.md similarity index 100% rename from docs/cudf/source/developer_guide/config.md rename to docs/cudf/source/developer_guide/options.md diff --git a/docs/cudf/source/user_guide/config.md b/docs/cudf/source/user_guide/config.md deleted file mode 100644 index 2a1063410c2..00000000000 --- a/docs/cudf/source/user_guide/config.md +++ /dev/null @@ -1,8 +0,0 @@ -# Options - -CUDF options are a set of key value pairs stored in a global dictionary. - -User may get the full list of cudf options with ``cudf.describe_option``. -To set value to a option, use ``cudf.set_option``. - -See [API reference](api.options) for detail. diff --git a/docs/cudf/source/user_guide/index.md b/docs/cudf/source/user_guide/index.md index 86098cecde6..d99056f69f2 100644 --- a/docs/cudf/source/user_guide/index.md +++ b/docs/cudf/source/user_guide/index.md @@ -12,6 +12,6 @@ groupby guide-to-udfs cupy-interop dask-cudf -config +options PandasCompat ``` diff --git a/docs/cudf/source/user_guide/options.md b/docs/cudf/source/user_guide/options.md new file mode 100644 index 00000000000..f390d91c8f6 --- /dev/null +++ b/docs/cudf/source/user_guide/options.md @@ -0,0 +1,9 @@ +# Options + +cuDF has an options API to configure and customize global behavior. +This API complements the [pandas.options](https://pandas.pydata.org/docs/user_guide/options.html) API with features specific to cuDF. + +User may get the full list of cudf options with {py:func}`cudf.describe_option` with no arguments. +To set value to a option, use {py:func}`cudf.set_option`. + +See [API reference](api.options) for detail. From 1210368ef61ad0b07862bab130a011f3e8068f49 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Mon, 18 Jul 2022 16:44:38 -0700 Subject: [PATCH 08/17] Address review comments --- python/cudf/cudf/__init__.py | 5 +- python/cudf/cudf/options.py | 75 ++++++++++++++------------ python/cudf/cudf/tests/test_options.py | 71 +++++++++++++++++------- 3 files changed, 97 insertions(+), 54 deletions(-) diff --git a/python/cudf/cudf/__init__.py b/python/cudf/cudf/__init__.py index 70471545ec0..4fd713406fc 100644 --- a/python/cudf/cudf/__init__.py +++ b/python/cudf/cudf/__init__.py @@ -82,7 +82,7 @@ from cudf.utils.dtypes import _NA_REP from cudf.utils.utils import set_allocator -from .options import ( +from cudf.options import ( get_option, set_option, describe_option, @@ -173,4 +173,7 @@ "to_datetime", "to_numeric", "unstack", + "get_option", + "set_option", + "describe_option", ] diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index 0fb46ec699c..93fa27eb638 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -1,46 +1,46 @@ # Copyright (c) 2022, NVIDIA CORPORATION. +import textwrap from dataclasses import dataclass from typing import Any, Callable, Dict, Optional, Union @dataclass -class CUDFOption: +class Option: + default: Any value: Any description: str validator: Callable -_CUDF_OPTIONS: Dict[str, CUDFOption] = {} +_OPTIONS: Dict[str, Option] = {} def _register_option( name: str, default_value: Any, description: str, validator: Callable ): - """Register an entry in the option dictionary. + """Register an option. Parameters ---------- name : str - The name of the option. Also used as the key in the dictionary. - + The name of the option. default_value : Any The default value of the option. - description : str A text description of the option. - validator : Callable - A function that returns ``True`` if a given value is valid for the - option, ``False`` otherwise. - """ - if not validator(default_value): - raise ValueError(f"Invalid default value: {default_value}") + Called on the option value to check its validity. Should raise an + error if the value is invalid. - _CUDF_OPTIONS[name] = CUDFOption(default_value, description, validator) + """ + validator(default_value) + _OPTIONS[name] = Option( + default_value, default_value, description, validator + ) -def get_option(key: str) -> Any: +def get_option(name: str) -> Any: """Get the value of option. Parameters @@ -52,41 +52,50 @@ def get_option(key: str) -> Any: ------- The value of the option. """ - return _CUDF_OPTIONS[key].value + return _OPTIONS[name].value -def set_option(key: str, val: Any): +def set_option(name: str, val: Any): """Set the value of option. Raises ``ValueError`` if the provided value is invalid. Parameters ---------- - key : str + name : str The name of the option. val : Any The value to set. """ - config = _CUDF_OPTIONS[key] - if not config.validator(val): - raise ValueError(f"Invalid option {val}") - config.value = val + option = _OPTIONS[name] + option.validator(val) + option.value = val -def describe_option(key: Optional[str] = None) -> Union[str, Dict[str, str]]: - """Returns a specific option description or all option descriptions. +def _build_option_description(name, opt): + return ( + f"{name}:\n" + f"\t{opt.description}\n" + f"\t[Default: {opt.default}] [Current: {opt.value}]" + ) + + +def describe_option(name: Optional[str] = None): + """Prints a specific option description or all option descriptions. + + If `name` is unspecified, prints all available option descriptions. Parameters ---------- - key : str + name : Optional[str] The name of the option. - - Returns - ------- - A string description of the option or a dictionary of all option - descriptions. """ - if key is None: - return {key: _CUDF_OPTIONS[key].description for key in _CUDF_OPTIONS} - - return _CUDF_OPTIONS[key].description + s = "" + if name is None: + s = "\n".join( + _build_option_description(name, opt) + for name, opt in _OPTIONS.items() + ) + else: + s = _build_option_description(name, _OPTIONS[name]) + print(s) diff --git a/python/cudf/cudf/tests/test_options.py b/python/cudf/cudf/tests/test_options.py index c1c4d0e580b..5b65b7dbf03 100644 --- a/python/cudf/cudf/tests/test_options.py +++ b/python/cudf/cudf/tests/test_options.py @@ -1,48 +1,79 @@ # Copyright (c) 2022, NVIDIA CORPORATION. +from contextlib import redirect_stdout +from io import StringIO + import pytest import cudf +@pytest.fixture(scope="module", autouse=True) +def empty_option_environment(): + old_option_enviorment = cudf.options._OPTIONS + cudf.options._OPTIONS = {} + yield + cudf.options._OPTIONS = old_option_enviorment + + @pytest.fixture(scope="module") -def odd_option(): +def odd_option(empty_option_environment): + def validator(x): + if not x % 2 == 1: + raise ValueError(f"Invalid option {x}") + cudf.options._register_option( - "odd_config", + "odd_option", 1, "An odd option.", - lambda x: x % 2 == 1, + validator, ) yield - cudf.options._CUDF_OPTIONS.pop("odd_config") + del cudf.options._OPTIONS["odd_option"] @pytest.fixture(scope="module") -def even_option(): +def even_option(empty_option_environment): + def validator(x): + if not x % 2 == 0: + raise ValueError(f"Invalid option {x}") + cudf.options._register_option( - "even_config", 0, "An even option.", lambda x: x % 2 == 0 + "even_option", 0, "An even option.", validator ) yield - cudf.options._CUDF_OPTIONS.pop("even_config") + del cudf.options._OPTIONS["even_option"] -def test_config_get_set(odd_option): - assert cudf.get_option("odd_config") == 1 - cudf.set_option("odd_config", 101) - assert cudf.get_option("odd_config") == 101 +def test_option_get_set(odd_option): + assert cudf.get_option("odd_option") == 1 + cudf.set_option("odd_option", 101) + assert cudf.get_option("odd_option") == 101 + # Restore default value for other tests + cudf.set_option("odd_option", 1) -def test_config_set_invalid(odd_option): +def test_option_set_invalid(odd_option): with pytest.raises(ValueError, match="Invalid option 0"): - cudf.set_option("odd_config", 0) + cudf.set_option("odd_option", 0) -def test_config_description(odd_option): - assert cudf.describe_option("odd_config") == "An odd option." +def test_option_description(odd_option): + s = StringIO() + with redirect_stdout(s): + cudf.describe_option("odd_option") + s.seek(0) + expected = "odd_option:\n\tAn odd option.\n\t[Default: 1] [Current: 1]\n" + assert expected == s.read() -def test_config_description_multi(odd_option, even_option): - assert cudf.describe_option() == { - "odd_config": "An odd option.", - "even_config": "An even option.", - } +def test_option_description_all(odd_option, even_option): + s = StringIO() + with redirect_stdout(s): + cudf.describe_option() + s.seek(0) + expected = ( + "odd_option:\n\tAn odd option.\n\t[Default: 1] [Current: 1]\n" + "even_option:\n\tAn even option.\n\t[Default: 0] [Current: 0]\n" + ) + assert expected == s.read() From f68c3032b76870f4fd30e96c5286acf8e212c543 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Mon, 18 Jul 2022 17:43:56 -0700 Subject: [PATCH 09/17] Address docs reviews --- docs/cudf/source/developer_guide/options.md | 10 +++++----- docs/cudf/source/user_guide/options.md | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/cudf/source/developer_guide/options.md b/docs/cudf/source/developer_guide/options.md index a0840626fc4..41298ab4d60 100644 --- a/docs/cudf/source/developer_guide/options.md +++ b/docs/cudf/source/developer_guide/options.md @@ -2,18 +2,18 @@ Options are stored as a dictionary in `cudf.options` module. Each option name is also its key in the dictionary. -The value of the option is an instance of a `CUDFOption` object. +The value of the option is an instance of a `Options` object. -A `CUDFOption` object has the following attributes: +A `Options` object has the following attributes: - `value`: the current value of the option - `description`: a text description of the option -- `validator`: a boolean function that returns `True` if value is valid, +- `validator`: a boolean function that returns `True` if `value` is valid, `False` otherwise. Developers can use `cudf.options._register_option` to add options to the dictionary. `cudf.get_option` is provided to get config value from the dictionary. When testing the behavior of a certain option, -it is advised to use [yield fixture](https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#yield-fixtures-recommended) to setup and cleanup the option. +it is advised to use [`yield` fixture](https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#yield-fixtures-recommended) to set up and clean up the option. -See [API reference](api.options) for detail. +See [API reference](api.options) for more details. diff --git a/docs/cudf/source/user_guide/options.md b/docs/cudf/source/user_guide/options.md index f390d91c8f6..599e210f478 100644 --- a/docs/cudf/source/user_guide/options.md +++ b/docs/cudf/source/user_guide/options.md @@ -3,7 +3,10 @@ cuDF has an options API to configure and customize global behavior. This API complements the [pandas.options](https://pandas.pydata.org/docs/user_guide/options.html) API with features specific to cuDF. -User may get the full list of cudf options with {py:func}`cudf.describe_option` with no arguments. +{py:func}`cudf.describe_option` will print the option's description, +the current and default value. +When no argument is provided, +all options are printed. To set value to a option, use {py:func}`cudf.set_option`. -See [API reference](api.options) for detail. +See [API reference](api.options) for more details. From 99201ba805097d6b8d39c36de97acb15c19325b6 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Mon, 18 Jul 2022 17:54:58 -0700 Subject: [PATCH 10/17] style fixes --- python/cudf/cudf/options.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index 93fa27eb638..e1c5d2f8aa5 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -1,8 +1,7 @@ # Copyright (c) 2022, NVIDIA CORPORATION. -import textwrap from dataclasses import dataclass -from typing import Any, Callable, Dict, Optional, Union +from typing import Any, Callable, Dict, Optional @dataclass From b741f1b0f9990880f21980428912c1ac98c23808 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Fri, 22 Jul 2022 14:32:06 -0700 Subject: [PATCH 11/17] Address docs review comments Co-authored-by: Charles Blackmon-Luca <20627856+charlesbluca@users.noreply.github.com> Co-authored-by: Lawrence Mitchell --- docs/cudf/source/developer_guide/options.md | 8 ++++---- docs/cudf/source/user_guide/options.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/cudf/source/developer_guide/options.md b/docs/cudf/source/developer_guide/options.md index 41298ab4d60..f9f17cd526c 100644 --- a/docs/cudf/source/developer_guide/options.md +++ b/docs/cudf/source/developer_guide/options.md @@ -2,18 +2,18 @@ Options are stored as a dictionary in `cudf.options` module. Each option name is also its key in the dictionary. -The value of the option is an instance of a `Options` object. +The value of the option is an instance of an `Options` object. -A `Options` object has the following attributes: +An `Options` object has the following attributes: - `value`: the current value of the option - `description`: a text description of the option - `validator`: a boolean function that returns `True` if `value` is valid, `False` otherwise. Developers can use `cudf.options._register_option` to add options to the dictionary. -`cudf.get_option` is provided to get config value from the dictionary. +{py:func}`cudf.get_option` is provided to get option values from the dictionary. When testing the behavior of a certain option, it is advised to use [`yield` fixture](https://docs.pytest.org/en/7.1.x/how-to/fixtures.html#yield-fixtures-recommended) to set up and clean up the option. -See [API reference](api.options) for more details. +See the [API reference](api.options) for more details. diff --git a/docs/cudf/source/user_guide/options.md b/docs/cudf/source/user_guide/options.md index 599e210f478..c919d522e35 100644 --- a/docs/cudf/source/user_guide/options.md +++ b/docs/cudf/source/user_guide/options.md @@ -9,4 +9,4 @@ When no argument is provided, all options are printed. To set value to a option, use {py:func}`cudf.set_option`. -See [API reference](api.options) for more details. +See the [API reference](api.options) for more details. From 4ac78be29a62f8f04f115f05cf40207deedbf702 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 26 Jul 2022 11:20:00 -0700 Subject: [PATCH 12/17] Apply review comments Co-authored-by: Bradley Dice --- docs/cudf/source/developer_guide/options.md | 4 ++-- docs/cudf/source/user_guide/options.md | 2 +- python/cudf/cudf/__init__.py | 6 +++--- python/cudf/cudf/options.py | 12 +++--------- python/cudf/cudf/tests/test_options.py | 10 ++++------ 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/docs/cudf/source/developer_guide/options.md b/docs/cudf/source/developer_guide/options.md index f9f17cd526c..7fbe0b7bede 100644 --- a/docs/cudf/source/developer_guide/options.md +++ b/docs/cudf/source/developer_guide/options.md @@ -1,7 +1,7 @@ # Options -Options are stored as a dictionary in `cudf.options` module. -Each option name is also its key in the dictionary. +Options are stored as a dictionary in the `cudf.options` module. +Each option name is its key in the dictionary. The value of the option is an instance of an `Options` object. An `Options` object has the following attributes: diff --git a/docs/cudf/source/user_guide/options.md b/docs/cudf/source/user_guide/options.md index c919d522e35..d634c2fbc74 100644 --- a/docs/cudf/source/user_guide/options.md +++ b/docs/cudf/source/user_guide/options.md @@ -4,7 +4,7 @@ cuDF has an options API to configure and customize global behavior. This API complements the [pandas.options](https://pandas.pydata.org/docs/user_guide/options.html) API with features specific to cuDF. {py:func}`cudf.describe_option` will print the option's description, -the current and default value. +the current value, and the default value. When no argument is provided, all options are printed. To set value to a option, use {py:func}`cudf.set_option`. diff --git a/python/cudf/cudf/__init__.py b/python/cudf/cudf/__init__.py index 4fd713406fc..fff311b251d 100644 --- a/python/cudf/cudf/__init__.py +++ b/python/cudf/cudf/__init__.py @@ -150,11 +150,13 @@ "concat", "cut", "date_range", + "describe_option", "factorize", "from_dataframe", "from_dlpack", "from_pandas", "get_dummies", + "get_option", "interval_range", "isclose", "melt", @@ -169,11 +171,9 @@ "read_parquet", "read_text", "set_allocator", + "set_option", "testing", "to_datetime", "to_numeric", "unstack", - "get_option", - "set_option", - "describe_option", ] diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index e1c5d2f8aa5..0b4133d8d03 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -89,12 +89,6 @@ def describe_option(name: Optional[str] = None): name : Optional[str] The name of the option. """ - s = "" - if name is None: - s = "\n".join( - _build_option_description(name, opt) - for name, opt in _OPTIONS.items() - ) - else: - s = _build_option_description(name, _OPTIONS[name]) - print(s) + names = _OPTIONS.keys() if name is None else [name] + for name in names: + print(_build_option_description(name, _OPTIONS[name]) diff --git a/python/cudf/cudf/tests/test_options.py b/python/cudf/cudf/tests/test_options.py index 5b65b7dbf03..ee44ee9ad8a 100644 --- a/python/cudf/cudf/tests/test_options.py +++ b/python/cudf/cudf/tests/test_options.py @@ -10,13 +10,13 @@ @pytest.fixture(scope="module", autouse=True) def empty_option_environment(): - old_option_enviorment = cudf.options._OPTIONS + old_option_environment = cudf.options._OPTIONS cudf.options._OPTIONS = {} yield - cudf.options._OPTIONS = old_option_enviorment + cudf.options._OPTIONS = old_option_environment -@pytest.fixture(scope="module") +@pytest.fixture def odd_option(empty_option_environment): def validator(x): if not x % 2 == 1: @@ -32,7 +32,7 @@ def validator(x): del cudf.options._OPTIONS["odd_option"] -@pytest.fixture(scope="module") +@pytest.fixture def even_option(empty_option_environment): def validator(x): if not x % 2 == 0: @@ -49,8 +49,6 @@ def test_option_get_set(odd_option): assert cudf.get_option("odd_option") == 1 cudf.set_option("odd_option", 101) assert cudf.get_option("odd_option") == 101 - # Restore default value for other tests - cudf.set_option("odd_option", 1) def test_option_set_invalid(odd_option): From f872c285c3210fbd5a177d65f75e3da013383ebc Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 26 Jul 2022 14:56:59 -0700 Subject: [PATCH 13/17] Add try except blocks and documents errors raised --- python/cudf/cudf/options.py | 44 +++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index 0b4133d8d03..67ae0410efe 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -31,9 +31,18 @@ def _register_option( validator : Callable Called on the option value to check its validity. Should raise an error if the value is invalid. - + + Raises + ------ + ValueError + If the provided value fails in validator. May be nested with custom + error raised by validator. """ - validator(default_value) + try: + validator(default_value) + except Exception as e: + raise ValueError(f"{name}={default_value} is not a valid value.") from e + _OPTIONS[name] = Option( default_value, default_value, description, validator ) @@ -50,24 +59,45 @@ def get_option(name: str) -> Any: Returns ------- The value of the option. + + Raises + ------ + KeyError + If option ``name`` does not exist. """ - return _OPTIONS[name].value + try: + return _OPTIONS[name].value + except KeyError: + raise KeyError(f'"{name}" is not a valid option.') def set_option(name: str, val: Any): """Set the value of option. - Raises ``ValueError`` if the provided value is invalid. - Parameters ---------- name : str The name of the option. val : Any The value to set. + + Raises + ------ + KeyError + If option ``name`` does not exist. + ValueError + If the provided value fails in validator. May be nested with custom + error raised by validator. """ - option = _OPTIONS[name] - option.validator(val) + try: + option = _OPTIONS[name] + except KeyError: + raise KeyError(f'"{name}" does not exist.') + try: + option.validator(val) + except Exception as e: + raise ValueError(f"{name}={val} is not a valid value.") from e + option.value = val From 7d018e1310eb12bcb50b85700bdb40dc5ccc4b2b Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 26 Jul 2022 14:57:43 -0700 Subject: [PATCH 14/17] minor grammar updates --- python/cudf/cudf/options.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index 67ae0410efe..e99060bfff8 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -110,9 +110,9 @@ def _build_option_description(name, opt): def describe_option(name: Optional[str] = None): - """Prints a specific option description or all option descriptions. + """Prints the description of an option. - If `name` is unspecified, prints all available option descriptions. + If `name` is unspecified, prints the description of all available options. Parameters ---------- From e0a2546d926bf9a589d2151dcb24eaee728a39ca Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 26 Jul 2022 16:15:25 -0700 Subject: [PATCH 15/17] removes try except block around validator --- python/cudf/cudf/options.py | 24 +++++++----------------- python/cudf/cudf/tests/test_options.py | 6 +++--- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index e99060bfff8..7bad4aae724 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -34,15 +34,10 @@ def _register_option( Raises ------ - ValueError - If the provided value fails in validator. May be nested with custom - error raised by validator. + BaseException + Raised by validator if the value is invalid. """ - try: - validator(default_value) - except Exception as e: - raise ValueError(f"{name}={default_value} is not a valid value.") from e - + validator(default_value) _OPTIONS[name] = Option( default_value, default_value, description, validator ) @@ -68,7 +63,7 @@ def get_option(name: str) -> Any: try: return _OPTIONS[name].value except KeyError: - raise KeyError(f'"{name}" is not a valid option.') + raise KeyError(f'"{name}" does not exist.') def set_option(name: str, val: Any): @@ -85,19 +80,14 @@ def set_option(name: str, val: Any): ------ KeyError If option ``name`` does not exist. - ValueError - If the provided value fails in validator. May be nested with custom - error raised by validator. + BaseException + Raised by validator if the value is invalid. """ try: option = _OPTIONS[name] except KeyError: raise KeyError(f'"{name}" does not exist.') - try: - option.validator(val) - except Exception as e: - raise ValueError(f"{name}={val} is not a valid value.") from e - + option.validator(val) option.value = val diff --git a/python/cudf/cudf/tests/test_options.py b/python/cudf/cudf/tests/test_options.py index ee44ee9ad8a..19ffb361542 100644 --- a/python/cudf/cudf/tests/test_options.py +++ b/python/cudf/cudf/tests/test_options.py @@ -20,7 +20,7 @@ def empty_option_environment(): def odd_option(empty_option_environment): def validator(x): if not x % 2 == 1: - raise ValueError(f"Invalid option {x}") + raise ValueError(f"Invalid option value {x}") cudf.options._register_option( "odd_option", @@ -36,7 +36,7 @@ def validator(x): def even_option(empty_option_environment): def validator(x): if not x % 2 == 0: - raise ValueError(f"Invalid option {x}") + raise ValueError(f"Invalid option value {x}") cudf.options._register_option( "even_option", 0, "An even option.", validator @@ -52,7 +52,7 @@ def test_option_get_set(odd_option): def test_option_set_invalid(odd_option): - with pytest.raises(ValueError, match="Invalid option 0"): + with pytest.raises(ValueError, match="Invalid option value 0"): cudf.set_option("odd_option", 0) From 6ab41b55db77da5e76312d460b8f1e58a7fb832a Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 26 Jul 2022 16:21:45 -0700 Subject: [PATCH 16/17] style fixes --- python/cudf/cudf/options.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/options.py b/python/cudf/cudf/options.py index 7bad4aae724..9c2991dd8d5 100644 --- a/python/cudf/cudf/options.py +++ b/python/cudf/cudf/options.py @@ -31,7 +31,7 @@ def _register_option( validator : Callable Called on the option value to check its validity. Should raise an error if the value is invalid. - + Raises ------ BaseException @@ -111,4 +111,4 @@ def describe_option(name: Optional[str] = None): """ names = _OPTIONS.keys() if name is None else [name] for name in names: - print(_build_option_description(name, _OPTIONS[name]) + print(_build_option_description(name, _OPTIONS[name])) From 438003c9518eb460252d0953349eb77c17ec6222 Mon Sep 17 00:00:00 2001 From: Michael Wang Date: Tue, 26 Jul 2022 16:39:42 -0700 Subject: [PATCH 17/17] Add one liner in dev guide --- docs/cudf/source/developer_guide/options.md | 3 +++ docs/cudf/source/user_guide/options.md | 2 ++ 2 files changed, 5 insertions(+) diff --git a/docs/cudf/source/developer_guide/options.md b/docs/cudf/source/developer_guide/options.md index 7fbe0b7bede..b977c0fdea4 100644 --- a/docs/cudf/source/developer_guide/options.md +++ b/docs/cudf/source/developer_guide/options.md @@ -1,5 +1,8 @@ # Options +The usage of options is explained in the [user guide](options_user_guide). +This document provides more explanations on how developers work with options internally. + Options are stored as a dictionary in the `cudf.options` module. Each option name is its key in the dictionary. The value of the option is an instance of an `Options` object. diff --git a/docs/cudf/source/user_guide/options.md b/docs/cudf/source/user_guide/options.md index d634c2fbc74..245d3fd1974 100644 --- a/docs/cudf/source/user_guide/options.md +++ b/docs/cudf/source/user_guide/options.md @@ -1,3 +1,5 @@ +(options_user_guide)= + # Options cuDF has an options API to configure and customize global behavior.