|
2 | 2 | TYPE_CHECKING,
|
3 | 3 | Any,
|
4 | 4 | Callable,
|
| 5 | + Literal, |
5 | 6 | Optional,
|
6 | 7 | )
|
7 | 8 |
|
@@ -48,3 +49,72 @@ 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_get_options(): |
| 55 | + # GH 1230 |
| 56 | + # Initial values |
| 57 | + check(assert_type(pd.options.display.chop_threshold, Optional[float]), type(None)) |
| 58 | + check(assert_type(pd.options.display.max_columns, Optional[int]), int) |
| 59 | + check(assert_type(pd.options.display.max_colwidth, Optional[int]), int) |
| 60 | + check(assert_type(pd.options.display.max_dir_items, Optional[int]), int) |
| 61 | + check(assert_type(pd.options.display.max_rows, Optional[int]), int) |
| 62 | + check(assert_type(pd.options.display.max_seq_items, Optional[int]), int) |
| 63 | + check(assert_type(pd.options.display.min_rows, Optional[int]), int) |
| 64 | + |
| 65 | + |
| 66 | +def test_display_types_none_allowed_set_options(): |
| 67 | + # GH 1230 |
| 68 | + # Test setting each option as None and then to a specific value |
| 69 | + pd.options.display.chop_threshold = None |
| 70 | + pd.options.display.chop_threshold = 0.9 |
| 71 | + pd.options.display.max_columns = None |
| 72 | + pd.options.display.max_columns = 100 |
| 73 | + pd.options.display.max_colwidth = None |
| 74 | + pd.options.display.max_colwidth = 100 |
| 75 | + pd.options.display.max_dir_items = None |
| 76 | + pd.options.display.max_dir_items = 100 |
| 77 | + pd.options.display.max_rows = None |
| 78 | + pd.options.display.max_rows = 100 |
| 79 | + pd.options.display.max_seq_items = None |
| 80 | + pd.options.display.max_seq_items = 100 |
| 81 | + pd.options.display.min_rows = None |
| 82 | + pd.options.display.min_rows = 100 |
| 83 | + |
| 84 | + |
| 85 | +def test_display_types_literal_constraints(): |
| 86 | + # GH 1230 |
| 87 | + # Various display options have specific allowed values |
| 88 | + # Test colheader_justify with allowed values |
| 89 | + assert_type(pd.options.display.colheader_justify, Literal["left", "right"]) |
| 90 | + pd.options.display.colheader_justify = "left" |
| 91 | + check(assert_type(pd.options.display.colheader_justify, Literal["left"]), str) |
| 92 | + pd.options.display.colheader_justify = "right" |
| 93 | + check(assert_type(pd.options.display.colheader_justify, Literal["right"]), str) |
| 94 | + |
| 95 | + # Test large_repr with allowed values |
| 96 | + assert_type(pd.options.display.large_repr, Literal["truncate", "info"]) |
| 97 | + pd.options.display.large_repr = "truncate" |
| 98 | + check(assert_type(pd.options.display.large_repr, Literal["truncate"]), str) |
| 99 | + pd.options.display.large_repr = "info" |
| 100 | + check(assert_type(pd.options.display.large_repr, Literal["info"]), str) |
| 101 | + |
| 102 | + # Test memory_usage with allowed values |
| 103 | + assert_type(pd.options.display.memory_usage, Optional[Literal[True, False, "deep"]]) |
| 104 | + pd.options.display.memory_usage = True |
| 105 | + check(assert_type(pd.options.display.memory_usage, Literal[True]), bool) |
| 106 | + pd.options.display.memory_usage = False |
| 107 | + check(assert_type(pd.options.display.memory_usage, Literal[False]), bool) |
| 108 | + pd.options.display.memory_usage = "deep" |
| 109 | + check(assert_type(pd.options.display.memory_usage, Literal["deep"]), str) |
| 110 | + pd.options.display.memory_usage = None |
| 111 | + check(assert_type(pd.options.display.memory_usage, None), type(None)) |
| 112 | + |
| 113 | + # Test show_dimensions with allowed values |
| 114 | + assert_type(pd.options.display.show_dimensions, Literal[True, False, "truncate"]) |
| 115 | + pd.options.display.show_dimensions = True |
| 116 | + check(assert_type(pd.options.display.show_dimensions, Literal[True]), bool) |
| 117 | + pd.options.display.show_dimensions = False |
| 118 | + check(assert_type(pd.options.display.show_dimensions, Literal[False]), bool) |
| 119 | + pd.options.display.show_dimensions = "truncate" |
| 120 | + check(assert_type(pd.options.display.show_dimensions, Literal["truncate"]), str) |
0 commit comments