Skip to content

Commit 4bcb200

Browse files
m-piliatwoertwein
authored andcommitted
pandas-devgh-544: Fix pd.options.display.float_format (pandas-dev#545)
Set the correct type for pd.options.display.float_format. Resolves pandas-dev#544
1 parent 4a992f5 commit 4bcb200

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pandas-stubs/_config/config.pyi

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
from collections.abc import Iterable
1+
from collections.abc import (
2+
Callable,
3+
Iterable,
4+
)
25
from contextlib import ContextDecorator
36
from typing import (
47
Any,
@@ -51,7 +54,7 @@ class Display(DictWrapper):
5154
date_yearfirst: bool
5255
encoding: str
5356
expand_frame_repr: bool
54-
float_format: str | None
57+
float_format: Callable[[float], str] | None
5558
html: DisplayHTML
5659
large_repr: str
5760
latex: DisplayLaTeX

tests/test_config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from typing import (
22
TYPE_CHECKING,
33
Any,
4+
Callable,
5+
Optional,
46
)
57

68
import pandas as pd
@@ -36,3 +38,13 @@ def test_specific_option():
3638
check(assert_type(pd.options.plotting.backend, str), str)
3739
# Just check assignment
3840
pd.options.plotting.backend = "matplotlib"
41+
42+
43+
def test_display_float_format():
44+
check(
45+
assert_type(pd.options.display.float_format, Optional[Callable[[float], str]]),
46+
type(None),
47+
)
48+
formatter = "{,.2f}".format
49+
with pd.option_context("display.float_format", formatter):
50+
assert pd.get_option("display.float_format") == formatter

0 commit comments

Comments
 (0)