|
2 | 2 | TYPE_CHECKING,
|
3 | 3 | Any,
|
4 | 4 | Callable,
|
| 5 | + Literal, |
5 | 6 | Optional,
|
6 | 7 | )
|
7 | 8 |
|
@@ -48,3 +49,78 @@ def test_display_float_format():
|
48 | 49 | formatter = "{,.2f}".format
|
49 | 50 | with pd.option_context("display.float_format", formatter):
|
50 | 51 | assert pd.get_option("display.float_format") == formatter
|
| 52 | + |
| 53 | + |
| 54 | +def test_display_types_none_allowed(): |
| 55 | + # GH 1230 |
| 56 | + # Initial values |
| 57 | + assert_type(pd.options.display.max_columns, Optional[int]) |
| 58 | + assert_type(pd.options.display.max_colwidth, Optional[int]) |
| 59 | + assert_type(pd.options.display.max_dir_items, Optional[int]) |
| 60 | + assert_type(pd.options.display.max_rows, Optional[int]) |
| 61 | + assert_type(pd.options.display.max_seq_items, Optional[int]) |
| 62 | + assert_type(pd.options.display.min_rows, Optional[int]) |
| 63 | + # Test with None |
| 64 | + pd.options.display.max_columns = None |
| 65 | + check(assert_type(pd.options.display.max_columns, None), type(None)) |
| 66 | + pd.options.display.max_colwidth = None |
| 67 | + check(assert_type(pd.options.display.max_colwidth, None), type(None)) |
| 68 | + pd.options.display.max_dir_items = None |
| 69 | + check(assert_type(pd.options.display.max_dir_items, None), type(None)) |
| 70 | + pd.options.display.max_rows = None |
| 71 | + check(assert_type(pd.options.display.max_rows, None), type(None)) |
| 72 | + pd.options.display.max_seq_items = None |
| 73 | + check(assert_type(pd.options.display.max_seq_items, None), type(None)) |
| 74 | + pd.options.display.min_rows = None |
| 75 | + check(assert_type(pd.options.display.min_rows, None), type(None)) |
| 76 | + # Test with integer values |
| 77 | + pd.options.display.max_columns = 100 |
| 78 | + check(assert_type(pd.options.display.max_columns, int), int) |
| 79 | + pd.options.display.max_colwidth = 100 |
| 80 | + check(assert_type(pd.options.display.max_colwidth, int), int) |
| 81 | + pd.options.display.max_dir_items = 100 |
| 82 | + check(assert_type(pd.options.display.max_dir_items, int), int) |
| 83 | + pd.options.display.max_rows = 100 |
| 84 | + check(assert_type(pd.options.display.max_rows, int), int) |
| 85 | + pd.options.display.max_seq_items = 100 |
| 86 | + check(assert_type(pd.options.display.max_seq_items, int), int) |
| 87 | + pd.options.display.min_rows = 100 |
| 88 | + check(assert_type(pd.options.display.min_rows, int), int) |
| 89 | + |
| 90 | + |
| 91 | +def test_display_types_literal_constraints(): |
| 92 | + # GH 1230 |
| 93 | + # Various display options have specific allowed values |
| 94 | + # Test colheader_justify with allowed values |
| 95 | + assert_type(pd.options.display.colheader_justify, Literal["left", "right"]) |
| 96 | + pd.options.display.colheader_justify = "left" |
| 97 | + check(assert_type(pd.options.display.colheader_justify, Literal["left"]), str) |
| 98 | + pd.options.display.colheader_justify = "right" |
| 99 | + check(assert_type(pd.options.display.colheader_justify, Literal["right"]), str) |
| 100 | + |
| 101 | + # Test large_repr with allowed values |
| 102 | + assert_type(pd.options.display.large_repr, Literal["truncate", "info"]) |
| 103 | + pd.options.display.large_repr = "truncate" |
| 104 | + check(assert_type(pd.options.display.large_repr, Literal["truncate"]), str) |
| 105 | + pd.options.display.large_repr = "info" |
| 106 | + check(assert_type(pd.options.display.large_repr, Literal["info"]), str) |
| 107 | + |
| 108 | + # Test memory_usage with allowed values |
| 109 | + assert_type(pd.options.display.memory_usage, Optional[Literal[True, False, "deep"]]) |
| 110 | + pd.options.display.memory_usage = True |
| 111 | + check(assert_type(pd.options.display.memory_usage, Literal[True]), bool) |
| 112 | + pd.options.display.memory_usage = False |
| 113 | + check(assert_type(pd.options.display.memory_usage, Literal[False]), bool) |
| 114 | + pd.options.display.memory_usage = "deep" |
| 115 | + check(assert_type(pd.options.display.memory_usage, Literal["deep"]), str) |
| 116 | + pd.options.display.memory_usage = None |
| 117 | + check(assert_type(pd.options.display.memory_usage, None), type(None)) |
| 118 | + |
| 119 | + # Test show_dimensions with allowed values |
| 120 | + assert_type(pd.options.display.show_dimensions, Literal[True, False, "truncate"]) |
| 121 | + pd.options.display.show_dimensions = True |
| 122 | + check(assert_type(pd.options.display.show_dimensions, Literal[True]), bool) |
| 123 | + pd.options.display.show_dimensions = False |
| 124 | + check(assert_type(pd.options.display.show_dimensions, Literal[False]), bool) |
| 125 | + pd.options.display.show_dimensions = "truncate" |
| 126 | + check(assert_type(pd.options.display.show_dimensions, Literal["truncate"]), str) |
0 commit comments