@@ -4,66 +4,142 @@ import pli from "./internals/polars_internal";
4
4
* Configure polars; offers options for table formatting and more.
5
5
*/
6
6
export interface Config {
7
- /** Use utf8 characters to print tables */
8
- setUtf8Tables ( ) : Config ;
9
- /** Use ascii characters to print tables */
7
+ /** Use ASCII characters to display table outlines.
8
+ * @param active - Set False to revert to the standard UTF8_FULL_CONDENSED formatting style. Default: true
9
+ *
10
+ * @example
11
+ * const df = pl.DataFrame({abc: [1.0, 2.5, 5.0], xyz: [true, false, true]})
12
+ pl.Config.setAsciiTables(true)
13
+ console.log(df.toString());
14
+ # shape: (3, 2) shape: (3, 2)
15
+ # ┌─────┬───────┐ +-----+-------+
16
+ # │ abc ┆ xyz │ | abc | xyz |
17
+ # │ --- ┆ --- │ | --- | --- |
18
+ # │ f64 ┆ bool │ | f64 | bool |
19
+ # ╞═════╪═══════╡ +=============+
20
+ # │ 1.0 ┆ true │ >> | 1.0 | true |
21
+ # │ 2.5 ┆ false │ | 2.5 | false |
22
+ # │ 5.0 ┆ true │ | 5.0 | true |
23
+ # └─────┴───────┘ +-----+-------+
24
+ */
10
25
setAsciiTables ( ) : Config ;
11
26
setAsciiTables ( active : boolean ) : Config ;
12
- /** Set the number of character used to draw the table */
27
+ /** Set the maximum width of a table in characters.
28
+ * @param width - Maximum table width in characters; if n < 0 (eg: -1), display full width.
29
+ *
30
+ * @example
31
+ * const df = pl.DataFrame({ id: ["SEQ1", "SEQ2"], seq: ["ATGATAAAGGAG", "GCAACGCATATA"] });
32
+ >>> df
33
+ shape: (2, 2)
34
+ ┌──────┬──────────────┐
35
+ │ id ┆ seq │
36
+ │ --- ┆ --- │
37
+ │ str ┆ str │
38
+ ╞══════╪══════════════╡
39
+ │ SEQ1 ┆ ATGATAAAGGAG │
40
+ │ SEQ2 ┆ GCAACGCATATA │
41
+ └──────┴──────────────┘
42
+ >>> pl.Config.setTblWidthChars(12);
43
+ >>> df
44
+ shape: (2, 2)
45
+ ┌─────┬─────┐
46
+ │ id ┆ seq │
47
+ │ --- ┆ --- │
48
+ │ str ┆ str │
49
+ ╞═════╪═════╡
50
+ │ SEQ ┆ ATG │
51
+ │ 1 ┆ ATA │
52
+ │ ┆ AAG │
53
+ │ ┆ GAG │
54
+ │ SEQ ┆ GCA │
55
+ │ 2 ┆ ACG │
56
+ │ ┆ CAT │
57
+ │ ┆ ATA │
58
+ └─────┴─────┘
59
+ */
60
+ setTblWidthChars ( ) : Config ;
13
61
setTblWidthChars ( width : number ) : Config ;
14
- /** Set the number of rows used to print tables */
62
+ /** Set the max number of rows used to draw the table (both Dataframe and Series).
63
+ * @param n - Number of rows to display; if `n < 0` (eg: -1), display all rows (DataFrame) and all elements (Series).
64
+ *
65
+ * @example
66
+ const df = pl.DataFrame( {abc: [1.0, 2.5, 3.5, 5.0], xyz: [True, False, True, False]} );
67
+ pl.Config.setTblRows(2);
68
+ console.log(df.toString());
69
+ shape: (4, 2)
70
+ ┌─────┬───────┐
71
+ │ abc ┆ xyz │
72
+ │ --- ┆ --- │
73
+ │ f64 ┆ bool │
74
+ ╞═════╪═══════╡
75
+ │ 1.0 ┆ true │
76
+ │ … ┆ … │
77
+ │ 5.0 ┆ false │
78
+ └─────┴───────┘
79
+ */
80
+ setTblRows ( ) : Config ;
15
81
setTblRows ( n : number ) : Config ;
16
- /** Set the number of columns used to print tables */
82
+ /** Set the number of columns that are visible when displaying tables.
83
+ * @param n - Number of columns to display; if `n < 0` (eg: -1), display all columns.
84
+ *
85
+ * @example
86
+
87
+ const df = pl.DataFrame( {abc: [1.0, 2.5, 3.5, 5.0], def: ["d", "e", "f", "g"], xyz: [true, false, true, false] } );
88
+ // Set number of displayed columns to a low value
89
+ pl.Config.setTblCols(2);
90
+ shape: (4, 3)
91
+ ┌─────┬───┬───────┐
92
+ │ abc ┆ … ┆ xyz │
93
+ │ --- ┆ ┆ --- │
94
+ │ f64 ┆ ┆ bool │
95
+ ╞═════╪═══╪═══════╡
96
+ │ 1.0 ┆ … ┆ true │
97
+ │ 2.5 ┆ … ┆ false │
98
+ │ 3.5 ┆ … ┆ true │
99
+ │ 5.0 ┆ … ┆ false │
100
+ └─────┴───┴───────┘
101
+ */
102
+ setTblCols ( ) : Config ;
17
103
setTblCols ( n : number ) : Config ;
18
104
105
+ // TODO: Implement these methods
19
106
// set_auto_structify
20
107
// set_decimal_separator
21
- // set_engine_affinity
108
+ // set_engine_affinity
22
109
// set_float_precision
23
110
// set_fmt_float
24
111
// set_fmt_str_lengths
25
112
// set_fmt_table_cell_list_len
26
113
// set_streaming_chunk_size
27
114
// set_tbl_cell_alignment
28
115
// set_tbl_cell_numeric_alignment
29
- // set_tbl_cols
30
116
// set_tbl_column_data_type_inline
31
117
// set_tbl_dataframe_shape_below
32
118
// set_tbl_formatting
33
119
// set_tbl_hide_column_data_types
34
120
// set_tbl_hide_column_names
35
121
// set_tbl_hide_dataframe_shape
36
122
// set_tbl_hide_dtype_separator
37
- // set_tbl_rows
38
- // set_tbl_width_chars
39
123
// set_thousands_separator
40
124
// set_trim_decimal_zeros
41
125
// set_verbose
42
-
43
126
}
44
127
45
- /**
46
- * @ignore
47
- */
48
128
export const Config : Config = {
49
- setUtf8Tables ( ) {
50
- process . env [ "POLARS_FMT_NO_UTF8" ] = undefined ;
51
- return this ;
52
- } ,
53
129
setAsciiTables ( active ?: boolean ) {
54
130
pli . setAsciiTables ( active ) ;
55
131
return this ;
56
132
} ,
57
- setTblWidthChars ( width ) {
58
- process . env [ "POLARS_TABLE_WIDTH" ] = String ( width ) ;
133
+ setTblWidthChars ( width ?: number ) {
134
+ pli . setTblWidthChars ( width ) ;
59
135
return this ;
60
136
} ,
61
- setTblRows ( n ) {
62
- process . env [ "POLARS_FMT_MAX_ROWS" ] = String ( n ) ;
137
+ setTblRows ( n ?: number ) {
138
+ pli . setTblRows ( n ) ;
63
139
return this ;
64
140
} ,
65
- setTblCols ( n ) {
66
- process . env [ "POLARS_FMT_MAX_COLS" ] = String ( n ) ;
141
+ setTblCols ( n ?: number ) {
142
+ pli . setTblCols ( n ) ;
67
143
return this ;
68
144
} ,
69
145
} ;
0 commit comments