Skip to content

Commit 7c1f996

Browse files
Improve types for pd.options.display.* properties
1 parent ba4ebd8 commit 7c1f996

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

pandas-stubs/_config/config.pyi

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,30 @@ class DisplayUnicode(DictWrapper):
4949

5050
class Display(DictWrapper):
5151
chop_threshold: int | None
52-
colheader_justify: str
52+
colheader_justify: Literal["left", "right"]
5353
date_dayfirst: bool
5454
date_yearfirst: bool
5555
encoding: str
5656
expand_frame_repr: bool
5757
float_format: Callable[[float], str] | None
5858
html: DisplayHTML
59-
large_repr: str
59+
large_repr: Literal["truncate", "info"]
6060
latex: DisplayLaTeX
6161
max_categories: int
62-
max_columns: int
63-
max_colwidth: int
64-
max_dir_items: int
62+
max_columns: int | None
63+
max_colwidth: int | None
64+
max_dir_items: int | None
6565
max_info_columns: int
6666
max_info_rows: int
67-
max_rows: int
68-
max_seq_items: int
69-
memory_usage: bool
70-
min_rows: int
67+
max_rows: int | None
68+
max_seq_items: int | None
69+
memory_usage: bool | Literal["deep"] | None
70+
min_rows: int | None
7171
multi_sparse: bool
7272
notebook_repr_html: bool
7373
pprint_nest_depth: int
7474
precision: int
75-
show_dimensions: str
75+
show_dimensions: bool | Literal["truncate"]
7676
unicode: DisplayUnicode
7777
width: int
7878

tests/test_config.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,46 @@ def test_display_float_format():
4848
formatter = "{,.2f}".format
4949
with pd.option_context("display.float_format", formatter):
5050
assert pd.get_option("display.float_format") == formatter
51+
52+
53+
def test_display_types_none_allowed():
54+
# GH 1230
55+
properties_to_test = [
56+
"max_columns",
57+
"max_colwidth",
58+
"max_dir_items",
59+
"max_rows",
60+
"max_seq_items",
61+
"min_rows",
62+
]
63+
for prop in properties_to_test:
64+
# Test with None
65+
setattr(pd.options.display, prop, None)
66+
check(assert_type(pd.get_option(f"display.{prop}"), Any), type(None))
67+
68+
# Test with integer values
69+
setattr(pd.options.display, prop, 100)
70+
check(assert_type(pd.get_option(f"display.{prop}"), Any), int)
71+
72+
73+
def test_display_types_literal_constraints():
74+
# GH 1230
75+
# Various display options have specific allowed values, check assignment
76+
# Test colheader_justify with allowed values
77+
pd.options.display.colheader_justify = "left"
78+
pd.options.display.colheader_justify = "right"
79+
80+
# Test large_repr with allowed values
81+
pd.options.display.large_repr = "truncate"
82+
pd.options.display.large_repr = "info"
83+
84+
# Test memory_usage with allowed values
85+
pd.options.display.memory_usage = True
86+
pd.options.display.memory_usage = False
87+
pd.options.display.memory_usage = "deep"
88+
pd.options.display.memory_usage = None
89+
90+
# Test show_dimensions with allowed values
91+
pd.options.display.show_dimensions = True
92+
pd.options.display.show_dimensions = False
93+
pd.options.display.show_dimensions = "truncate"

0 commit comments

Comments
 (0)