config_init.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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 then in the module.
  9. """
  10. import pandas.core.config as cf
  11. from pandas.core.config import (
  12. is_bool, is_callable, is_instance_factory, is_int, is_one_of_factory,
  13. is_text)
  14. from pandas.io.formats.console import detect_console_encoding
  15. from pandas.io.formats.terminal import is_terminal
  16. # compute
  17. use_bottleneck_doc = """
  18. : bool
  19. Use the bottleneck library to accelerate if it is installed,
  20. the default is True
  21. Valid values: False,True
  22. """
  23. def use_bottleneck_cb(key):
  24. from pandas.core import nanops
  25. nanops.set_use_bottleneck(cf.get_option(key))
  26. use_numexpr_doc = """
  27. : bool
  28. Use the numexpr library to accelerate computation if it is installed,
  29. the default is True
  30. Valid values: False,True
  31. """
  32. def use_numexpr_cb(key):
  33. from pandas.core.computation import expressions
  34. expressions.set_use_numexpr(cf.get_option(key))
  35. with cf.config_prefix('compute'):
  36. cf.register_option('use_bottleneck', True, use_bottleneck_doc,
  37. validator=is_bool, cb=use_bottleneck_cb)
  38. cf.register_option('use_numexpr', True, use_numexpr_doc,
  39. validator=is_bool, cb=use_numexpr_cb)
  40. #
  41. # options from the "display" namespace
  42. pc_precision_doc = """
  43. : int
  44. Floating point output precision (number of significant digits). This is
  45. only a suggestion
  46. """
  47. pc_colspace_doc = """
  48. : int
  49. Default space for DataFrame columns.
  50. """
  51. pc_max_rows_doc = """
  52. : int
  53. If max_rows is exceeded, switch to truncate view. Depending on
  54. `large_repr`, objects are either centrally truncated or printed as
  55. a summary view. 'None' value means unlimited.
  56. In case python/IPython is running in a terminal and `large_repr`
  57. equals 'truncate' this can be set to 0 and pandas will auto-detect
  58. the height of the terminal and print a truncated object which fits
  59. the screen height. The IPython notebook, IPython qtconsole, or
  60. IDLE do not run in a terminal and hence it is not possible to do
  61. correct auto-detection.
  62. """
  63. pc_max_cols_doc = """
  64. : int
  65. If max_cols is exceeded, switch to truncate view. Depending on
  66. `large_repr`, objects are either centrally truncated or printed as
  67. a summary view. 'None' value means unlimited.
  68. In case python/IPython is running in a terminal and `large_repr`
  69. equals 'truncate' this can be set to 0 and pandas will auto-detect
  70. the width of the terminal and print a truncated object which fits
  71. the screen width. The IPython notebook, IPython qtconsole, or IDLE
  72. do not run in a terminal and hence it is not possible to do
  73. correct auto-detection.
  74. """
  75. pc_max_categories_doc = """
  76. : int
  77. This sets the maximum number of categories pandas should output when
  78. printing out a `Categorical` or a Series of dtype "category".
  79. """
  80. pc_max_info_cols_doc = """
  81. : int
  82. max_info_columns is used in DataFrame.info method to decide if
  83. per column information will be printed.
  84. """
  85. pc_nb_repr_h_doc = """
  86. : boolean
  87. When True, IPython notebook will use html representation for
  88. pandas objects (if it is available).
  89. """
  90. pc_date_dayfirst_doc = """
  91. : boolean
  92. When True, prints and parses dates with the day first, eg 20/01/2005
  93. """
  94. pc_date_yearfirst_doc = """
  95. : boolean
  96. When True, prints and parses dates with the year first, eg 2005/01/20
  97. """
  98. pc_pprint_nest_depth = """
  99. : int
  100. Controls the number of nested levels to process when pretty-printing
  101. """
  102. pc_multi_sparse_doc = """
  103. : boolean
  104. "sparsify" MultiIndex display (don't display repeated
  105. elements in outer levels within groups)
  106. """
  107. pc_encoding_doc = """
  108. : str/unicode
  109. Defaults to the detected encoding of the console.
  110. Specifies the encoding to be used for strings returned by to_string,
  111. these are generally strings meant to be displayed on the console.
  112. """
  113. float_format_doc = """
  114. : callable
  115. The callable should accept a floating point number and return
  116. a string with the desired format of the number. This is used
  117. in some places like SeriesFormatter.
  118. See formats.format.EngFormatter for an example.
  119. """
  120. max_colwidth_doc = """
  121. : int
  122. The maximum width in characters of a column in the repr of
  123. a pandas data structure. When the column overflows, a "..."
  124. placeholder is embedded in the output.
  125. """
  126. colheader_justify_doc = """
  127. : 'left'/'right'
  128. Controls the justification of column headers. used by DataFrameFormatter.
  129. """
  130. pc_expand_repr_doc = """
  131. : boolean
  132. Whether to print out the full DataFrame repr for wide DataFrames across
  133. multiple lines, `max_columns` is still respected, but the output will
  134. wrap-around across multiple "pages" if its width exceeds `display.width`.
  135. """
  136. pc_show_dimensions_doc = """
  137. : boolean or 'truncate'
  138. Whether to print out dimensions at the end of DataFrame repr.
  139. If 'truncate' is specified, only print out the dimensions if the
  140. frame is truncated (e.g. not display all rows and/or columns)
  141. """
  142. pc_east_asian_width_doc = """
  143. : boolean
  144. Whether to use the Unicode East Asian Width to calculate the display text
  145. width.
  146. Enabling this may affect to the performance (default: False)
  147. """
  148. pc_ambiguous_as_wide_doc = """
  149. : boolean
  150. Whether to handle Unicode characters belong to Ambiguous as Wide (width=2)
  151. (default: False)
  152. """
  153. pc_latex_repr_doc = """
  154. : boolean
  155. Whether to produce a latex DataFrame representation for jupyter
  156. environments that support it.
  157. (default: False)
  158. """
  159. pc_table_schema_doc = """
  160. : boolean
  161. Whether to publish a Table Schema representation for frontends
  162. that support it.
  163. (default: False)
  164. """
  165. pc_html_border_doc = """
  166. : int
  167. A ``border=value`` attribute is inserted in the ``<table>`` tag
  168. for the DataFrame HTML repr.
  169. """
  170. pc_html_border_deprecation_warning = """\
  171. html.border has been deprecated, use display.html.border instead
  172. (currently both are identical)
  173. """
  174. pc_html_use_mathjax_doc = """\
  175. : boolean
  176. When True, Jupyter notebook will process table contents using MathJax,
  177. rendering mathematical expressions enclosed by the dollar symbol.
  178. (default: True)
  179. """
  180. pc_width_doc = """
  181. : int
  182. Width of the display in characters. In case python/IPython is running in
  183. a terminal this can be set to None and pandas will correctly auto-detect
  184. the width.
  185. Note that the IPython notebook, IPython qtconsole, or IDLE do not run in a
  186. terminal and hence it is not possible to correctly detect the width.
  187. """
  188. pc_chop_threshold_doc = """
  189. : float or None
  190. if set to a float value, all float values smaller then the given threshold
  191. will be displayed as exactly 0 by repr and friends.
  192. """
  193. pc_max_seq_items = """
  194. : int or None
  195. when pretty-printing a long sequence, no more then `max_seq_items`
  196. will be printed. If items are omitted, they will be denoted by the
  197. addition of "..." to the resulting string.
  198. If set to None, the number of items to be printed is unlimited.
  199. """
  200. pc_max_info_rows_doc = """
  201. : int or None
  202. df.info() will usually show null-counts for each column.
  203. For large frames this can be quite slow. max_info_rows and max_info_cols
  204. limit this null check only to frames with smaller dimensions than
  205. specified.
  206. """
  207. pc_large_repr_doc = """
  208. : 'truncate'/'info'
  209. For DataFrames exceeding max_rows/max_cols, the repr (and HTML repr) can
  210. show a truncated table (the default from 0.13), or switch to the view from
  211. df.info() (the behaviour in earlier versions of pandas).
  212. """
  213. pc_memory_usage_doc = """
  214. : bool, string or None
  215. This specifies if the memory usage of a DataFrame should be displayed when
  216. df.info() is called. Valid values True,False,'deep'
  217. """
  218. pc_latex_escape = """
  219. : bool
  220. This specifies if the to_latex method of a Dataframe uses escapes special
  221. characters.
  222. Valid values: False,True
  223. """
  224. pc_latex_longtable = """
  225. :bool
  226. This specifies if the to_latex method of a Dataframe uses the longtable
  227. format.
  228. Valid values: False,True
  229. """
  230. pc_latex_multicolumn = """
  231. : bool
  232. This specifies if the to_latex method of a Dataframe uses multicolumns
  233. to pretty-print MultiIndex columns.
  234. Valid values: False,True
  235. """
  236. pc_latex_multicolumn_format = """
  237. : string
  238. This specifies the format for multicolumn headers.
  239. Can be surrounded with '|'.
  240. Valid values: 'l', 'c', 'r', 'p{<width>}'
  241. """
  242. pc_latex_multirow = """
  243. : bool
  244. This specifies if the to_latex method of a Dataframe uses multirows
  245. to pretty-print MultiIndex rows.
  246. Valid values: False,True
  247. """
  248. style_backup = dict()
  249. def table_schema_cb(key):
  250. from pandas.io.formats.printing import _enable_data_resource_formatter
  251. _enable_data_resource_formatter(cf.get_option(key))
  252. with cf.config_prefix('display'):
  253. cf.register_option('precision', 6, pc_precision_doc, validator=is_int)
  254. cf.register_option('float_format', None, float_format_doc,
  255. validator=is_one_of_factory([None, is_callable]))
  256. cf.register_option('column_space', 12, validator=is_int)
  257. cf.register_option('max_info_rows', 1690785, pc_max_info_rows_doc,
  258. validator=is_instance_factory((int, type(None))))
  259. cf.register_option('max_rows', 60, pc_max_rows_doc,
  260. validator=is_instance_factory([type(None), int]))
  261. cf.register_option('max_categories', 8, pc_max_categories_doc,
  262. validator=is_int)
  263. cf.register_option('max_colwidth', 50, max_colwidth_doc, validator=is_int)
  264. if is_terminal():
  265. max_cols = 0 # automatically determine optimal number of columns
  266. else:
  267. max_cols = 20 # cannot determine optimal number of columns
  268. cf.register_option('max_columns', max_cols, pc_max_cols_doc,
  269. validator=is_instance_factory([type(None), int]))
  270. cf.register_option('large_repr', 'truncate', pc_large_repr_doc,
  271. validator=is_one_of_factory(['truncate', 'info']))
  272. cf.register_option('max_info_columns', 100, pc_max_info_cols_doc,
  273. validator=is_int)
  274. cf.register_option('colheader_justify', 'right', colheader_justify_doc,
  275. validator=is_text)
  276. cf.register_option('notebook_repr_html', True, pc_nb_repr_h_doc,
  277. validator=is_bool)
  278. cf.register_option('date_dayfirst', False, pc_date_dayfirst_doc,
  279. validator=is_bool)
  280. cf.register_option('date_yearfirst', False, pc_date_yearfirst_doc,
  281. validator=is_bool)
  282. cf.register_option('pprint_nest_depth', 3, pc_pprint_nest_depth,
  283. validator=is_int)
  284. cf.register_option('multi_sparse', True, pc_multi_sparse_doc,
  285. validator=is_bool)
  286. cf.register_option('encoding', detect_console_encoding(), pc_encoding_doc,
  287. validator=is_text)
  288. cf.register_option('expand_frame_repr', True, pc_expand_repr_doc)
  289. cf.register_option('show_dimensions', 'truncate', pc_show_dimensions_doc,
  290. validator=is_one_of_factory([True, False, 'truncate']))
  291. cf.register_option('chop_threshold', None, pc_chop_threshold_doc)
  292. cf.register_option('max_seq_items', 100, pc_max_seq_items)
  293. cf.register_option('width', 80, pc_width_doc,
  294. validator=is_instance_factory([type(None), int]))
  295. cf.register_option('memory_usage', True, pc_memory_usage_doc,
  296. validator=is_one_of_factory([None, True,
  297. False, 'deep']))
  298. cf.register_option('unicode.east_asian_width', False,
  299. pc_east_asian_width_doc, validator=is_bool)
  300. cf.register_option('unicode.ambiguous_as_wide', False,
  301. pc_east_asian_width_doc, validator=is_bool)
  302. cf.register_option('latex.repr', False,
  303. pc_latex_repr_doc, validator=is_bool)
  304. cf.register_option('latex.escape', True, pc_latex_escape,
  305. validator=is_bool)
  306. cf.register_option('latex.longtable', False, pc_latex_longtable,
  307. validator=is_bool)
  308. cf.register_option('latex.multicolumn', True, pc_latex_multicolumn,
  309. validator=is_bool)
  310. cf.register_option('latex.multicolumn_format', 'l', pc_latex_multicolumn,
  311. validator=is_text)
  312. cf.register_option('latex.multirow', False, pc_latex_multirow,
  313. validator=is_bool)
  314. cf.register_option('html.table_schema', False, pc_table_schema_doc,
  315. validator=is_bool, cb=table_schema_cb)
  316. cf.register_option('html.border', 1, pc_html_border_doc,
  317. validator=is_int)
  318. cf.register_option('html.use_mathjax', True, pc_html_use_mathjax_doc,
  319. validator=is_bool)
  320. with cf.config_prefix('html'):
  321. cf.register_option('border', 1, pc_html_border_doc,
  322. validator=is_int)
  323. cf.deprecate_option('html.border', msg=pc_html_border_deprecation_warning,
  324. rkey='display.html.border')
  325. tc_sim_interactive_doc = """
  326. : boolean
  327. Whether to simulate interactive mode for purposes of testing
  328. """
  329. with cf.config_prefix('mode'):
  330. cf.register_option('sim_interactive', False, tc_sim_interactive_doc)
  331. use_inf_as_null_doc = """
  332. : boolean
  333. use_inf_as_null had been deprecated and will be removed in a future
  334. version. Use `use_inf_as_na` instead.
  335. """
  336. use_inf_as_na_doc = """
  337. : boolean
  338. True means treat None, NaN, INF, -INF as NA (old way),
  339. False means None and NaN are null, but INF, -INF are not NA
  340. (new way).
  341. """
  342. # We don't want to start importing everything at the global context level
  343. # or we'll hit circular deps.
  344. def use_inf_as_na_cb(key):
  345. from pandas.core.dtypes.missing import _use_inf_as_na
  346. _use_inf_as_na(key)
  347. with cf.config_prefix('mode'):
  348. cf.register_option('use_inf_as_na', False, use_inf_as_na_doc,
  349. cb=use_inf_as_na_cb)
  350. cf.register_option('use_inf_as_null', False, use_inf_as_null_doc,
  351. cb=use_inf_as_na_cb)
  352. cf.deprecate_option('mode.use_inf_as_null', msg=use_inf_as_null_doc,
  353. rkey='mode.use_inf_as_na')
  354. # user warnings
  355. chained_assignment = """
  356. : string
  357. Raise an exception, warn, or no action if trying to use chained assignment,
  358. The default is warn
  359. """
  360. with cf.config_prefix('mode'):
  361. cf.register_option('chained_assignment', 'warn', chained_assignment,
  362. validator=is_one_of_factory([None, 'warn', 'raise']))
  363. # Set up the io.excel specific configuration.
  364. writer_engine_doc = """
  365. : string
  366. The default Excel writer engine for '{ext}' files. Available options:
  367. auto, {others}.
  368. """
  369. _xls_options = ['xlwt']
  370. _xlsm_options = ['openpyxl']
  371. _xlsx_options = ['openpyxl', 'xlsxwriter']
  372. with cf.config_prefix("io.excel.xls"):
  373. cf.register_option("writer", "auto",
  374. writer_engine_doc.format(
  375. ext='xls',
  376. others=', '.join(_xls_options)),
  377. validator=str)
  378. with cf.config_prefix("io.excel.xlsm"):
  379. cf.register_option("writer", "auto",
  380. writer_engine_doc.format(
  381. ext='xlsm',
  382. others=', '.join(_xlsm_options)),
  383. validator=str)
  384. with cf.config_prefix("io.excel.xlsx"):
  385. cf.register_option("writer", "auto",
  386. writer_engine_doc.format(
  387. ext='xlsx',
  388. others=', '.join(_xlsx_options)),
  389. validator=str)
  390. # Set up the io.parquet specific configuration.
  391. parquet_engine_doc = """
  392. : string
  393. The default parquet reader/writer engine. Available options:
  394. 'auto', 'pyarrow', 'fastparquet', the default is 'auto'
  395. """
  396. with cf.config_prefix('io.parquet'):
  397. cf.register_option(
  398. 'engine', 'auto', parquet_engine_doc,
  399. validator=is_one_of_factory(['auto', 'pyarrow', 'fastparquet']))
  400. # --------
  401. # Plotting
  402. # ---------
  403. register_converter_doc = """
  404. : bool
  405. Whether to register converters with matplotlib's units registry for
  406. dates, times, datetimes, and Periods. Toggling to False will remove
  407. the converters, restoring any converters that pandas overwrote.
  408. """
  409. def register_converter_cb(key):
  410. from pandas.plotting import register_matplotlib_converters
  411. from pandas.plotting import deregister_matplotlib_converters
  412. if cf.get_option(key):
  413. register_matplotlib_converters()
  414. else:
  415. deregister_matplotlib_converters()
  416. with cf.config_prefix("plotting.matplotlib"):
  417. cf.register_option("register_converters", True, register_converter_doc,
  418. validator=bool, cb=register_converter_cb)