Skip to content

Commit f7447cc

Browse files
authored
BUG: option_context with invalid option (pandas-dev#62726)
1 parent 6e27e26 commit f7447cc

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

pandas/_config/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ def option_context(*args) -> Generator[None]:
503503
)
504504

505505
ops = tuple(zip(args[::2], args[1::2], strict=True))
506+
undo: tuple[tuple[Any, Any], ...] = ()
506507
try:
507508
undo = tuple((pat, get_option(pat)) for pat, val in ops)
508509
for pat, val in ops:

pandas/tests/config/test_config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,9 @@ def test_no_silent_downcasting_deprecated():
491491
cf.get_option("future.no_silent_downcasting")
492492
with tm.assert_produces_warning(Pandas4Warning, match="is deprecated"):
493493
cf.set_option("future.no_silent_downcasting", True)
494+
495+
496+
def test_option_context_invalid_option():
497+
with pytest.raises(OptionError, match="No such keys"):
498+
with cf.option_context("invalid", True):
499+
pass

0 commit comments

Comments
 (0)