Skip to content
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

config.register_option allows registering invalid options #29242

Open
simonjayhawkins opened this issue Oct 27, 2019 · 6 comments
Open

config.register_option allows registering invalid options #29242

simonjayhawkins opened this issue Oct 27, 2019 · 6 comments
Labels
Bug Error Reporting Incorrect or improved errors from pandas

Comments

@simonjayhawkins
Copy link
Member

>>> import pandas as pd
>>>
>>> pd.__version__
'0.26.0.dev0+684.g953757a3e'
>>>
>>> from pandas._config import config
>>>
>>> config.register_option("a.b.c", 1)
>>>
>>> config.get_option("a.b.c")
1
>>>
>>> config.register_option("a.b.c", 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\simon\pandas\pandas\_config\config.py", line 445, in register_option
    raise OptionError(msg.format(key=key))
pandas._config.config.OptionError: "Option 'a.b.c' has already been registered"
>>>
>>> config.register_option("a.b", {"c": 2})
>>>
>>> config.get_option("a.b.c")
2
>>>
@jreback
Copy link
Contributor

jreback commented Oct 27, 2019

why would you not want this? it’s a pretty clear message

@simonjayhawkins
Copy link
Member Author

if a.b.c is registered you shouldn't be able to register a.b

@simonjayhawkins
Copy link
Member Author

simonjayhawkins commented Oct 27, 2019

>>> import pandas as pd
>>>
>>> pd.__version__
'0.26.0.dev0+684.g953757a3e'
>>>
>>> from pandas._config import config
>>>
>>> config.get_option("a.b.c")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\simon\pandas\pandas\_config\config.py", line 233, in __call__
    return self.__func__(*args, **kwds)
  File "C:\Users\simon\pandas\pandas\_config\config.py", line 102, in _get_option
    key = _get_single_key(pat, silent)
  File "C:\Users\simon\pandas\pandas\_config\config.py", line 88, in _get_single_key
    raise OptionError("No such keys(s): {pat!r}".format(pat=pat))
pandas._config.config.OptionError: "No such keys(s): 'a.b.c'"
>>>
>>> config.register_option("a.b.c", 1)
>>>
>>> config.get_option("a.b.c")
1
>>>
>>> config.register_option("a.b.c", 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\simon\pandas\pandas\_config\config.py", line 445, in register_option
    raise OptionError(msg.format(key=key))
pandas._config.config.OptionError: "Option 'a.b.c' has already been registered"
>>>
>>> config.register_option("a.b", "foo")
>>>
>>> config.get_option("a.b.c")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\simon\pandas\pandas\_config\config.py", line 233, in __call__
    return self.__func__(*args, **kwds)
  File "C:\Users\simon\pandas\pandas\_config\config.py", line 106, in _get_option
    return root[k]
TypeError: string indices must be integers
>>>

@jreback
Copy link
Contributor

jreback commented Oct 27, 2019

i would be more concerned with registering invalid options

@simonjayhawkins
Copy link
Member Author

i'll update the title

@simonjayhawkins simonjayhawkins changed the title config.register_option allows re-registering previously registered option. config.register_option allows registering invalid options Oct 27, 2019
@mroeschke mroeschke added the Error Reporting Incorrect or improved errors from pandas label Jul 22, 2021
@robbiesumner
Copy link

Does this need fixing? I would be happy to get working on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

No branches or pull requests

4 participants