Skip to content

Commit a21cdb4

Browse files
author
y-p
committed
ENH: add is_one_of_factory option validator factory
1 parent 60a8575 commit a21cdb4

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/core/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,14 @@ def inner(x):
703703

704704
return inner
705705

706+
def is_one_of_factory(legal_values):
707+
def inner(x):
708+
from pandas.core.common import pprint_thing as pp
709+
if not x in legal_values:
710+
pp_values = map(pp, legal_values)
711+
raise ValueError("Value must be one of %s" % pp("|".join(pp_values)))
712+
713+
return inner
706714

707715
# common type validators, for convenience
708716
# usage: register_option(... , validator = is_int)

pandas/core/config_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pandas.core.config as cf
22
from pandas.core.config import (is_int, is_bool, is_text, is_float,
3-
is_instance_factory)
3+
is_instance_factory,is_one_of_factory)
44
from pandas.core.format import detect_console_encoding
55

66
"""

0 commit comments

Comments
 (0)