config_init.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  1. """
  2. This module is imported from the pandas package __init__.py file
  3. in order to ensure that the core.config options registered here will
  4. be available as soon as the user loads the package. if register_option
  5. is invoked inside specific modules, they will not be registered until that
  6. module is imported, which may or may not be a problem.
  7. If you need to make sure options are available even before a certain
  8. module is imported, register them here rather than in the module.
  9. """
  10. from __future__ import annotations
  11. import os
  12. from typing import Callable
  13. import pandas._config.config as cf
  14. from pandas._config.config import (
  15. is_bool,
  16. is_callable,
  17. is_instance_factory,
  18. is_int,
  19. is_nonnegative_int,
  20. is_one_of_factory,
  21. is_str,
  22. is_text,
  23. )
  24. # compute
  25. use_bottleneck_doc = """
  26. : bool
  27. Use the bottleneck library to accelerate if it is installed,
  28. the default is True
  29. Valid values: False,True
  30. """
  31. def use_bottleneck_cb(key) -> None:
  32. from pandas.core import nanops
  33. nanops.set_use_bottleneck(cf.get_option(key))
  34. use_numexpr_doc = """
  35. : bool
  36. Use the numexpr library to accelerate computation if it is installed,
  37. the default is True
  38. Valid values: False,True
  39. """
  40. def use_numexpr_cb(key) -> None:
  41. from pandas.core.computation import expressions
  42. expressions.set_use_numexpr(cf.get_option(key))
  43. use_numba_doc = """
  44. : bool
  45. Use the numba engine option for select operations if it is installed,
  46. the default is False
  47. Valid values: False,True
  48. """
  49. def use_numba_cb(key) -> None:
  50. from pandas.core.util import numba_
  51. numba_.set_use_numba(cf.get_option(key))
  52. with cf.config_prefix("compute"):
  53. cf.register_option(
  54. "use_bottleneck",
  55. True,
  56. use_bottleneck_doc,
  57. validator=is_bool,
  58. cb=use_bottleneck_cb,
  59. )
  60. cf.register_option(
  61. "use_numexpr", True, use_numexpr_doc, validator=is_bool, cb=use_numexpr_cb
  62. )
  63. cf.register_option(
  64. "use_numba", False, use_numba_doc, validator=is_bool, cb=use_numba_cb
  65. )
  66. #
  67. # options from the "display" namespace
  68. pc_precision_doc = """
  69. : int
  70. Floating point output precision in terms of number of places after the
  71. decimal, for regular formatting as well as scientific notation. Similar
  72. to ``precision`` in :meth:`numpy.set_printoptions`.
  73. """
  74. pc_colspace_doc = """
  75. : int
  76. Default space for DataFrame columns.
  77. """
  78. pc_max_rows_doc = """
  79. : int
  80. If max_rows is exceeded, switch to truncate view. Depending on
  81. `large_repr`, objects are either centrally truncated or printed as
  82. a summary view. 'None' value means unlimited.
  83. In case python/IPython is running in a terminal and `large_repr`
  84. equals 'truncate' this can be set to 0 and pandas will auto-detect
  85. the height of the terminal and print a truncated object which fits
  86. the screen height. The IPython notebook, IPython qtconsole, or
  87. IDLE do not run in a terminal and hence it is not possible to do
  88. correct auto-detection.
  89. """
  90. pc_min_rows_doc = """
  91. : int
  92. The numbers of rows to show in a truncated view (when `max_rows` is
  93. exceeded). Ignored when `max_rows` is set to None or 0. When set to
  94. None, follows the value of `max_rows`.
  95. """
  96. pc_max_cols_doc = """
  97. : int
  98. If max_cols is exceeded, switch to truncate view. Depending on
  99. `large_repr`, objects are either centrally truncated or printed as
  100. a summary view. 'None' value means unlimited.
  101. In case python/IPython is running in a terminal and `large_repr`
  102. equals 'truncate' this can be set to 0 or None and pandas will auto-detect
  103. the width of the terminal and print a truncated object which fits
  104. the screen width. The IPython notebook, IPython qtconsole, or IDLE
  105. do not run in a terminal and hence it is not possible to do
  106. correct auto-detection and defaults to 20.
  107. """
  108. pc_max_categories_doc = """
  109. : int
  110. This sets the maximum number of categories pandas should output when
  111. printing out a `Categorical` or a Series of dtype "category".
  112. """
  113. pc_max_info_cols_doc = """
  114. : int
  115. max_info_columns is used in DataFrame.info method to decide if
  116. per column information will be printed.
  117. """
  118. pc_nb_repr_h_doc = """
  119. : boolean
  120. When True, IPython notebook will use html representation for
  121. pandas objects (if it is available).
  122. """
  123. pc_pprint_nest_depth = """
  124. : int
  125. Controls the number of nested levels to process when pretty-printing
  126. """
  127. pc_multi_sparse_doc = """
  128. : boolean
  129. "sparsify" MultiIndex display (don't display repeated
  130. elements in outer levels within groups)
  131. """
  132. float_format_doc = """
  133. : callable
  134. The callable should accept a floating point number and return
  135. a string with the desired format of the number. This is used
  136. in some places like SeriesFormatter.
  137. See formats.format.EngFormatter for an example.
  138. """
  139. max_colwidth_doc = """
  140. : int or None
  141. The maximum width in characters of a column in the repr of
  142. a pandas data structure. When the column overflows, a "..."
  143. placeholder is embedded in the output. A 'None' value means unlimited.
  144. """
  145. colheader_justify_doc = """
  146. : 'left'/'right'
  147. Controls the justification of column headers. used by DataFrameFormatter.
  148. """
  149. pc_expand_repr_doc = """
  150. : boolean
  151. Whether to print out the full DataFrame repr for wide DataFrames across
  152. multiple lines, `max_columns` is still respected, but the output will
  153. wrap-around across multiple "pages" if its width exceeds `display.width`.
  154. """
  155. pc_show_dimensions_doc = """
  156. : boolean or 'truncate'
  157. Whether to print out dimensions at the end of DataFrame repr.
  158. If 'truncate' is specified, only print out the dimensions if the
  159. frame is truncated (e.g. not display all rows and/or columns)
  160. """
  161. pc_east_asian_width_doc = """
  162. : boolean
  163. Whether to use the Unicode East Asian Width to calculate the display text
  164. width.
  165. Enabling this may affect to the performance (default: False)
  166. """
  167. pc_ambiguous_as_wide_doc = """
  168. : boolean
  169. Whether to handle Unicode characters belong to Ambiguous as Wide (width=2)
  170. (default: False)
  171. """
  172. pc_table_schema_doc = """
  173. : boolean
  174. Whether to publish a Table Schema representation for frontends
  175. that support it.
  176. (default: False)
  177. """
  178. pc_html_border_doc = """
  179. : int
  180. A ``border=value`` attribute is inserted in the ``<table>`` tag
  181. for the DataFrame HTML repr.
  182. """
  183. pc_html_use_mathjax_doc = """\
  184. : boolean
  185. When True, Jupyter notebook will process table contents using MathJax,
  186. rendering mathematical expressions enclosed by the dollar symbol.
  187. (default: True)
  188. """
  189. pc_max_dir_items = """\
  190. : int
  191. The number of items that will be added to `dir(...)`. 'None' value means
  192. unlimited. Because dir is cached, changing this option will not immediately
  193. affect already existing dataframes until a column is deleted or added.
  194. This is for instance used to suggest columns from a dataframe to tab
  195. completion.
  196. """
  197. pc_width_doc = """
  198. : int
  199. Width of the display in characters. In case python/IPython is running in
  200. a terminal this can be set to None and pandas will correctly auto-detect
  201. the width.
  202. Note that the IPython notebook, IPython qtconsole, or IDLE do not run in a
  203. terminal and hence it is not possible to correctly detect the width.
  204. """
  205. pc_chop_threshold_doc = """
  206. : float or None
  207. if set to a float value, all float values smaller than the given threshold
  208. will be displayed as exactly 0 by repr and friends.
  209. """
  210. pc_max_seq_items = """
  211. : int or None
  212. When pretty-printing a long sequence, no more then `max_seq_items`
  213. will be printed. If items are omitted, they will be denoted by the
  214. addition of "..." to the resulting string.
  215. If set to None, the number of items to be printed is unlimited.
  216. """
  217. pc_max_info_rows_doc = """
  218. : int or None
  219. df.info() will usually show null-counts for each column.
  220. For large frames this can be quite slow. max_info_rows and max_info_cols
  221. limit this null check only to frames with smaller dimensions than
  222. specified.
  223. """
  224. pc_large_repr_doc = """
  225. : 'truncate'/'info'
  226. For DataFrames exceeding max_rows/max_cols, the repr (and HTML repr) can
  227. show a truncated table (the default from 0.13), or switch to the view from
  228. df.info() (the behaviour in earlier versions of pandas).
  229. """
  230. pc_memory_usage_doc = """
  231. : bool, string or None
  232. This specifies if the memory usage of a DataFrame should be displayed when
  233. df.info() is called. Valid values True,False,'deep'
  234. """
  235. def table_schema_cb(key) -> None:
  236. from pandas.io.formats.printing import enable_data_resource_formatter
  237. enable_data_resource_formatter(cf.get_option(key))
  238. def is_terminal() -> bool:
  239. """
  240. Detect if Python is running in a terminal.
  241. Returns True if Python is running in a terminal or False if not.
  242. """
  243. try:
  244. # error: Name 'get_ipython' is not defined
  245. ip = get_ipython() # type: ignore[name-defined]
  246. except NameError: # assume standard Python interpreter in a terminal
  247. return True
  248. else:
  249. if hasattr(ip, "kernel"): # IPython as a Jupyter kernel
  250. return False
  251. else: # IPython in a terminal
  252. return True
  253. with cf.config_prefix("display"):
  254. cf.register_option("precision", 6, pc_precision_doc, validator=is_nonnegative_int)
  255. cf.register_option(
  256. "float_format",
  257. None,
  258. float_format_doc,
  259. validator=is_one_of_factory([None, is_callable]),
  260. )
  261. cf.register_option(
  262. "max_info_rows",
  263. 1690785,
  264. pc_max_info_rows_doc,
  265. validator=is_instance_factory((int, type(None))),
  266. )
  267. cf.register_option("max_rows", 60, pc_max_rows_doc, validator=is_nonnegative_int)
  268. cf.register_option(
  269. "min_rows",
  270. 10,
  271. pc_min_rows_doc,
  272. validator=is_instance_factory([type(None), int]),
  273. )
  274. cf.register_option("max_categories", 8, pc_max_categories_doc, validator=is_int)
  275. cf.register_option(
  276. "max_colwidth",
  277. 50,
  278. max_colwidth_doc,
  279. validator=is_nonnegative_int,
  280. )
  281. if is_terminal():
  282. max_cols = 0 # automatically determine optimal number of columns
  283. else:
  284. max_cols = 20 # cannot determine optimal number of columns
  285. cf.register_option(
  286. "max_columns", max_cols, pc_max_cols_doc, validator=is_nonnegative_int
  287. )
  288. cf.register_option(
  289. "large_repr",
  290. "truncate",
  291. pc_large_repr_doc,
  292. validator=is_one_of_factory(["truncate", "info"]),
  293. )
  294. cf.register_option("max_info_columns", 100, pc_max_info_cols_doc, validator=is_int)
  295. cf.register_option(
  296. "colheader_justify", "right", colheader_justify_doc, validator=is_text
  297. )
  298. cf.register_option("notebook_repr_html", True, pc_nb_repr_h_doc, validator=is_bool)
  299. cf.register_option("pprint_nest_depth", 3, pc_pprint_nest_depth, validator=is_int)
  300. cf.register_option("multi_sparse", True, pc_multi_sparse_doc, validator=is_bool)
  301. cf.register_option("expand_frame_repr", True, pc_expand_repr_doc)
  302. cf.register_option(
  303. "show_dimensions",
  304. "truncate",
  305. pc_show_dimensions_doc,
  306. validator=is_one_of_factory([True, False, "truncate"]),
  307. )
  308. cf.register_option("chop_threshold", None, pc_chop_threshold_doc)
  309. cf.register_option("max_seq_items", 100, pc_max_seq_items)
  310. cf.register_option(
  311. "width", 80, pc_width_doc, validator=is_instance_factory([type(None), int])
  312. )
  313. cf.register_option(
  314. "memory_usage",
  315. True,
  316. pc_memory_usage_doc,
  317. validator=is_one_of_factory([None, True, False, "deep"]),
  318. )
  319. cf.register_option(
  320. "unicode.east_asian_width", False, pc_east_asian_width_doc, validator=is_bool
  321. )
  322. cf.register_option(
  323. "unicode.ambiguous_as_wide", False, pc_east_asian_width_doc, validator=is_bool
  324. )
  325. cf.register_option(
  326. "html.table_schema",
  327. False,
  328. pc_table_schema_doc,
  329. validator=is_bool,
  330. cb=table_schema_cb,
  331. )
  332. cf.register_option("html.border", 1, pc_html_border_doc, validator=is_int)
  333. cf.register_option(
  334. "html.use_mathjax", True, pc_html_use_mathjax_doc, validator=is_bool
  335. )
  336. cf.register_option(
  337. "max_dir_items", 100, pc_max_dir_items, validator=is_nonnegative_int
  338. )
  339. tc_sim_interactive_doc = """
  340. : boolean
  341. Whether to simulate interactive mode for purposes of testing
  342. """
  343. with cf.config_prefix("mode"):
  344. cf.register_option("sim_interactive", False, tc_sim_interactive_doc)
  345. use_inf_as_na_doc = """
  346. : boolean
  347. True means treat None, NaN, INF, -INF as NA (old way),
  348. False means None and NaN are null, but INF, -INF are not NA
  349. (new way).
  350. """
  351. # We don't want to start importing everything at the global context level
  352. # or we'll hit circular deps.
  353. def use_inf_as_na_cb(key) -> None:
  354. from pandas.core.dtypes.missing import _use_inf_as_na
  355. _use_inf_as_na(key)
  356. with cf.config_prefix("mode"):
  357. cf.register_option("use_inf_as_na", False, use_inf_as_na_doc, cb=use_inf_as_na_cb)
  358. data_manager_doc = """
  359. : string
  360. Internal data manager type; can be "block" or "array". Defaults to "block",
  361. unless overridden by the 'PANDAS_DATA_MANAGER' environment variable (needs
  362. to be set before pandas is imported).
  363. """
  364. with cf.config_prefix("mode"):
  365. cf.register_option(
  366. "data_manager",
  367. # Get the default from an environment variable, if set, otherwise defaults
  368. # to "block". This environment variable can be set for testing.
  369. os.environ.get("PANDAS_DATA_MANAGER", "block"),
  370. data_manager_doc,
  371. validator=is_one_of_factory(["block", "array"]),
  372. )
  373. # TODO better name?
  374. copy_on_write_doc = """
  375. : bool
  376. Use new copy-view behaviour using Copy-on-Write. Defaults to False,
  377. unless overridden by the 'PANDAS_COPY_ON_WRITE' environment variable
  378. (if set to "1" for True, needs to be set before pandas is imported).
  379. """
  380. with cf.config_prefix("mode"):
  381. cf.register_option(
  382. "copy_on_write",
  383. # Get the default from an environment variable, if set, otherwise defaults
  384. # to False. This environment variable can be set for testing.
  385. os.environ.get("PANDAS_COPY_ON_WRITE", "0") == "1",
  386. copy_on_write_doc,
  387. validator=is_bool,
  388. )
  389. # user warnings
  390. chained_assignment = """
  391. : string
  392. Raise an exception, warn, or no action if trying to use chained assignment,
  393. The default is warn
  394. """
  395. with cf.config_prefix("mode"):
  396. cf.register_option(
  397. "chained_assignment",
  398. "warn",
  399. chained_assignment,
  400. validator=is_one_of_factory([None, "warn", "raise"]),
  401. )
  402. string_storage_doc = """
  403. : string
  404. The default storage for StringDtype.
  405. """
  406. with cf.config_prefix("mode"):
  407. cf.register_option(
  408. "string_storage",
  409. "python",
  410. string_storage_doc,
  411. validator=is_one_of_factory(["python", "pyarrow"]),
  412. )
  413. # Set up the io.excel specific reader configuration.
  414. reader_engine_doc = """
  415. : string
  416. The default Excel reader engine for '{ext}' files. Available options:
  417. auto, {others}.
  418. """
  419. _xls_options = ["xlrd"]
  420. _xlsm_options = ["xlrd", "openpyxl"]
  421. _xlsx_options = ["xlrd", "openpyxl"]
  422. _ods_options = ["odf"]
  423. _xlsb_options = ["pyxlsb"]
  424. with cf.config_prefix("io.excel.xls"):
  425. cf.register_option(
  426. "reader",
  427. "auto",
  428. reader_engine_doc.format(ext="xls", others=", ".join(_xls_options)),
  429. validator=is_one_of_factory(_xls_options + ["auto"]),
  430. )
  431. with cf.config_prefix("io.excel.xlsm"):
  432. cf.register_option(
  433. "reader",
  434. "auto",
  435. reader_engine_doc.format(ext="xlsm", others=", ".join(_xlsm_options)),
  436. validator=is_one_of_factory(_xlsm_options + ["auto"]),
  437. )
  438. with cf.config_prefix("io.excel.xlsx"):
  439. cf.register_option(
  440. "reader",
  441. "auto",
  442. reader_engine_doc.format(ext="xlsx", others=", ".join(_xlsx_options)),
  443. validator=is_one_of_factory(_xlsx_options + ["auto"]),
  444. )
  445. with cf.config_prefix("io.excel.ods"):
  446. cf.register_option(
  447. "reader",
  448. "auto",
  449. reader_engine_doc.format(ext="ods", others=", ".join(_ods_options)),
  450. validator=is_one_of_factory(_ods_options + ["auto"]),
  451. )
  452. with cf.config_prefix("io.excel.xlsb"):
  453. cf.register_option(
  454. "reader",
  455. "auto",
  456. reader_engine_doc.format(ext="xlsb", others=", ".join(_xlsb_options)),
  457. validator=is_one_of_factory(_xlsb_options + ["auto"]),
  458. )
  459. # Set up the io.excel specific writer configuration.
  460. writer_engine_doc = """
  461. : string
  462. The default Excel writer engine for '{ext}' files. Available options:
  463. auto, {others}.
  464. """
  465. _xlsm_options = ["openpyxl"]
  466. _xlsx_options = ["openpyxl", "xlsxwriter"]
  467. _ods_options = ["odf"]
  468. with cf.config_prefix("io.excel.xlsm"):
  469. cf.register_option(
  470. "writer",
  471. "auto",
  472. writer_engine_doc.format(ext="xlsm", others=", ".join(_xlsm_options)),
  473. validator=str,
  474. )
  475. with cf.config_prefix("io.excel.xlsx"):
  476. cf.register_option(
  477. "writer",
  478. "auto",
  479. writer_engine_doc.format(ext="xlsx", others=", ".join(_xlsx_options)),
  480. validator=str,
  481. )
  482. with cf.config_prefix("io.excel.ods"):
  483. cf.register_option(
  484. "writer",
  485. "auto",
  486. writer_engine_doc.format(ext="ods", others=", ".join(_ods_options)),
  487. validator=str,
  488. )
  489. # Set up the io.parquet specific configuration.
  490. parquet_engine_doc = """
  491. : string
  492. The default parquet reader/writer engine. Available options:
  493. 'auto', 'pyarrow', 'fastparquet', the default is 'auto'
  494. """
  495. with cf.config_prefix("io.parquet"):
  496. cf.register_option(
  497. "engine",
  498. "auto",
  499. parquet_engine_doc,
  500. validator=is_one_of_factory(["auto", "pyarrow", "fastparquet"]),
  501. )
  502. # Set up the io.sql specific configuration.
  503. sql_engine_doc = """
  504. : string
  505. The default sql reader/writer engine. Available options:
  506. 'auto', 'sqlalchemy', the default is 'auto'
  507. """
  508. with cf.config_prefix("io.sql"):
  509. cf.register_option(
  510. "engine",
  511. "auto",
  512. sql_engine_doc,
  513. validator=is_one_of_factory(["auto", "sqlalchemy"]),
  514. )
  515. # --------
  516. # Plotting
  517. # ---------
  518. plotting_backend_doc = """
  519. : str
  520. The plotting backend to use. The default value is "matplotlib", the
  521. backend provided with pandas. Other backends can be specified by
  522. providing the name of the module that implements the backend.
  523. """
  524. def register_plotting_backend_cb(key) -> None:
  525. if key == "matplotlib":
  526. # We defer matplotlib validation, since it's the default
  527. return
  528. from pandas.plotting._core import _get_plot_backend
  529. _get_plot_backend(key)
  530. with cf.config_prefix("plotting"):
  531. cf.register_option(
  532. "backend",
  533. defval="matplotlib",
  534. doc=plotting_backend_doc,
  535. validator=register_plotting_backend_cb,
  536. )
  537. register_converter_doc = """
  538. : bool or 'auto'.
  539. Whether to register converters with matplotlib's units registry for
  540. dates, times, datetimes, and Periods. Toggling to False will remove
  541. the converters, restoring any converters that pandas overwrote.
  542. """
  543. def register_converter_cb(key) -> None:
  544. from pandas.plotting import (
  545. deregister_matplotlib_converters,
  546. register_matplotlib_converters,
  547. )
  548. if cf.get_option(key):
  549. register_matplotlib_converters()
  550. else:
  551. deregister_matplotlib_converters()
  552. with cf.config_prefix("plotting.matplotlib"):
  553. cf.register_option(
  554. "register_converters",
  555. "auto",
  556. register_converter_doc,
  557. validator=is_one_of_factory(["auto", True, False]),
  558. cb=register_converter_cb,
  559. )
  560. # ------
  561. # Styler
  562. # ------
  563. styler_sparse_index_doc = """
  564. : bool
  565. Whether to sparsify the display of a hierarchical index. Setting to False will
  566. display each explicit level element in a hierarchical key for each row.
  567. """
  568. styler_sparse_columns_doc = """
  569. : bool
  570. Whether to sparsify the display of hierarchical columns. Setting to False will
  571. display each explicit level element in a hierarchical key for each column.
  572. """
  573. styler_render_repr = """
  574. : str
  575. Determine which output to use in Jupyter Notebook in {"html", "latex"}.
  576. """
  577. styler_max_elements = """
  578. : int
  579. The maximum number of data-cell (<td>) elements that will be rendered before
  580. trimming will occur over columns, rows or both if needed.
  581. """
  582. styler_max_rows = """
  583. : int, optional
  584. The maximum number of rows that will be rendered. May still be reduced to
  585. satsify ``max_elements``, which takes precedence.
  586. """
  587. styler_max_columns = """
  588. : int, optional
  589. The maximum number of columns that will be rendered. May still be reduced to
  590. satsify ``max_elements``, which takes precedence.
  591. """
  592. styler_precision = """
  593. : int
  594. The precision for floats and complex numbers.
  595. """
  596. styler_decimal = """
  597. : str
  598. The character representation for the decimal separator for floats and complex.
  599. """
  600. styler_thousands = """
  601. : str, optional
  602. The character representation for thousands separator for floats, int and complex.
  603. """
  604. styler_na_rep = """
  605. : str, optional
  606. The string representation for values identified as missing.
  607. """
  608. styler_escape = """
  609. : str, optional
  610. Whether to escape certain characters according to the given context; html or latex.
  611. """
  612. styler_formatter = """
  613. : str, callable, dict, optional
  614. A formatter object to be used as default within ``Styler.format``.
  615. """
  616. styler_multirow_align = """
  617. : {"c", "t", "b"}
  618. The specifier for vertical alignment of sparsified LaTeX multirows.
  619. """
  620. styler_multicol_align = r"""
  621. : {"r", "c", "l", "naive-l", "naive-r"}
  622. The specifier for horizontal alignment of sparsified LaTeX multicolumns. Pipe
  623. decorators can also be added to non-naive values to draw vertical
  624. rules, e.g. "\|r" will draw a rule on the left side of right aligned merged cells.
  625. """
  626. styler_hrules = """
  627. : bool
  628. Whether to add horizontal rules on top and bottom and below the headers.
  629. """
  630. styler_environment = """
  631. : str
  632. The environment to replace ``\\begin{table}``. If "longtable" is used results
  633. in a specific longtable environment format.
  634. """
  635. styler_encoding = """
  636. : str
  637. The encoding used for output HTML and LaTeX files.
  638. """
  639. styler_mathjax = """
  640. : bool
  641. If False will render special CSS classes to table attributes that indicate Mathjax
  642. will not be used in Jupyter Notebook.
  643. """
  644. with cf.config_prefix("styler"):
  645. cf.register_option("sparse.index", True, styler_sparse_index_doc, validator=is_bool)
  646. cf.register_option(
  647. "sparse.columns", True, styler_sparse_columns_doc, validator=is_bool
  648. )
  649. cf.register_option(
  650. "render.repr",
  651. "html",
  652. styler_render_repr,
  653. validator=is_one_of_factory(["html", "latex"]),
  654. )
  655. cf.register_option(
  656. "render.max_elements",
  657. 2**18,
  658. styler_max_elements,
  659. validator=is_nonnegative_int,
  660. )
  661. cf.register_option(
  662. "render.max_rows",
  663. None,
  664. styler_max_rows,
  665. validator=is_nonnegative_int,
  666. )
  667. cf.register_option(
  668. "render.max_columns",
  669. None,
  670. styler_max_columns,
  671. validator=is_nonnegative_int,
  672. )
  673. cf.register_option("render.encoding", "utf-8", styler_encoding, validator=is_str)
  674. cf.register_option("format.decimal", ".", styler_decimal, validator=is_str)
  675. cf.register_option(
  676. "format.precision", 6, styler_precision, validator=is_nonnegative_int
  677. )
  678. cf.register_option(
  679. "format.thousands",
  680. None,
  681. styler_thousands,
  682. validator=is_instance_factory([type(None), str]),
  683. )
  684. cf.register_option(
  685. "format.na_rep",
  686. None,
  687. styler_na_rep,
  688. validator=is_instance_factory([type(None), str]),
  689. )
  690. cf.register_option(
  691. "format.escape",
  692. None,
  693. styler_escape,
  694. validator=is_one_of_factory([None, "html", "latex"]),
  695. )
  696. cf.register_option(
  697. "format.formatter",
  698. None,
  699. styler_formatter,
  700. validator=is_instance_factory([type(None), dict, Callable, str]),
  701. )
  702. cf.register_option("html.mathjax", True, styler_mathjax, validator=is_bool)
  703. cf.register_option(
  704. "latex.multirow_align",
  705. "c",
  706. styler_multirow_align,
  707. validator=is_one_of_factory(["c", "t", "b", "naive"]),
  708. )
  709. val_mca = ["r", "|r|", "|r", "r|", "c", "|c|", "|c", "c|", "l", "|l|", "|l", "l|"]
  710. val_mca += ["naive-l", "naive-r"]
  711. cf.register_option(
  712. "latex.multicol_align",
  713. "r",
  714. styler_multicol_align,
  715. validator=is_one_of_factory(val_mca),
  716. )
  717. cf.register_option("latex.hrules", False, styler_hrules, validator=is_bool)
  718. cf.register_option(
  719. "latex.environment",
  720. None,
  721. styler_environment,
  722. validator=is_instance_factory([type(None), str]),
  723. )