itables 2.2.5__tar.gz → 2.4.0rc0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. {itables-2.2.5 → itables-2.4.0rc0}/.gitignore +5 -1
  2. {itables-2.2.5 → itables-2.4.0rc0}/PKG-INFO +29 -18
  3. {itables-2.2.5 → itables-2.4.0rc0}/README.md +20 -14
  4. itables-2.4.0rc0/itables/__init__.py +18 -0
  5. itables-2.4.0rc0/itables/dash.py +15 -0
  6. itables-2.4.0rc0/itables/datatables_format.py +147 -0
  7. {itables-2.2.5/src → itables-2.4.0rc0}/itables/downsample.py +14 -11
  8. itables-2.4.0rc0/itables/html/datatables_template.html +14 -0
  9. itables-2.4.0rc0/itables/html/dt_bundle.css +1 -0
  10. itables-2.4.0rc0/itables/html/dt_bundle.js +144 -0
  11. itables-2.4.0rc0/itables/html/init_datatables.html +4 -0
  12. {itables-2.2.5/src → itables-2.4.0rc0}/itables/interactive.py +1 -1
  13. itables-2.4.0rc0/itables/itables_for_streamlit/asset-manifest.json +13 -0
  14. {itables-2.2.5/src → itables-2.4.0rc0}/itables/itables_for_streamlit/index.html +1 -1
  15. itables-2.4.0rc0/itables/itables_for_streamlit/static/css/main.fffc57ef.css +2 -0
  16. itables-2.4.0rc0/itables/itables_for_streamlit/static/css/main.fffc57ef.css.map +1 -0
  17. itables-2.4.0rc0/itables/itables_for_streamlit/static/js/main.b7a7da42.js +3 -0
  18. itables-2.2.5/src/itables/itables_for_streamlit/static/js/main.f651d116.js.LICENSE.txt → itables-2.4.0rc0/itables/itables_for_streamlit/static/js/main.b7a7da42.js.LICENSE.txt +10 -10
  19. itables-2.4.0rc0/itables/itables_for_streamlit/static/js/main.b7a7da42.js.map +1 -0
  20. itables-2.4.0rc0/itables/javascript.py +809 -0
  21. itables-2.4.0rc0/itables/options.py +99 -0
  22. {itables-2.2.5/src → itables-2.4.0rc0}/itables/sample_dfs.py +43 -29
  23. {itables-2.2.5/src → itables-2.4.0rc0}/itables/shiny.py +15 -12
  24. itables-2.4.0rc0/itables/streamlit.py +16 -0
  25. itables-2.4.0rc0/itables/typing.py +187 -0
  26. {itables-2.2.5/src → itables-2.4.0rc0}/itables/utils.py +1 -1
  27. {itables-2.2.5/src → itables-2.4.0rc0}/itables/version.py +1 -1
  28. itables-2.4.0rc0/itables/widget/__init__.py +108 -0
  29. itables-2.4.0rc0/itables/widget/static/widget.css +1 -0
  30. itables-2.4.0rc0/itables/widget/static/widget.js +144 -0
  31. itables-2.4.0rc0/itables_for_dash/ITable.py +74 -0
  32. itables-2.4.0rc0/itables_for_dash/__init__.py +59 -0
  33. itables-2.4.0rc0/itables_for_dash/_imports_.py +5 -0
  34. itables-2.4.0rc0/itables_for_dash/async-ITable.js +3 -0
  35. itables-2.4.0rc0/itables_for_dash/async-ITable.js.LICENSE.txt +77 -0
  36. itables-2.4.0rc0/itables_for_dash/async-ITable.js.map +1 -0
  37. itables-2.4.0rc0/itables_for_dash/itables_for_dash.min.js +2 -0
  38. itables-2.4.0rc0/itables_for_dash/itables_for_dash.min.js.map +1 -0
  39. itables-2.4.0rc0/itables_for_dash/metadata.json +1 -0
  40. itables-2.4.0rc0/itables_for_dash/package-info.json +37 -0
  41. itables-2.4.0rc0/itables_for_dash/properties.py +83 -0
  42. {itables-2.2.5 → itables-2.4.0rc0}/pyproject.toml +13 -5
  43. itables-2.2.5/.gitattributes +0 -1
  44. itables-2.2.5/.github/codecov.yml +0 -21
  45. itables-2.2.5/.github/workflows/comment-pr.yml +0 -30
  46. itables-2.2.5/.github/workflows/continuous-integration.yml +0 -124
  47. itables-2.2.5/.github/workflows/publish-book.yml +0 -57
  48. itables-2.2.5/.github/workflows/publish.yml +0 -31
  49. itables-2.2.5/.pre-commit-config.yaml +0 -41
  50. itables-2.2.5/.pylintrc +0 -3
  51. itables-2.2.5/binder/labconfig/default_setting_overrides.json +0 -13
  52. itables-2.2.5/binder/postBuild +0 -16
  53. itables-2.2.5/binder/requirements.txt +0 -2
  54. itables-2.2.5/docs/_config.yml +0 -20
  55. itables-2.2.5/docs/_toc.yml +0 -34
  56. itables-2.2.5/docs/advanced_parameters.md +0 -220
  57. itables-2.2.5/docs/changelog.md +0 -583
  58. itables-2.2.5/docs/contributing.md +0 -72
  59. itables-2.2.5/docs/custom_css.md +0 -187
  60. itables-2.2.5/docs/custom_extensions.md +0 -112
  61. itables-2.2.5/docs/dark_mode.md +0 -28
  62. itables-2.2.5/docs/dash.md +0 -4
  63. itables-2.2.5/docs/developing.md +0 -101
  64. itables-2.2.5/docs/df_example.png +0 -0
  65. itables-2.2.5/docs/downsampling.md +0 -61
  66. itables-2.2.5/docs/extensions.md +0 -278
  67. itables-2.2.5/docs/formatting.md +0 -172
  68. itables-2.2.5/docs/html_export.md +0 -41
  69. itables-2.2.5/docs/images/code.png +0 -0
  70. itables-2.2.5/docs/images/colab.png +0 -0
  71. itables-2.2.5/docs/images/html.png +0 -0
  72. itables-2.2.5/docs/images/lab.png +0 -0
  73. itables-2.2.5/docs/images/notebook.png +0 -0
  74. itables-2.2.5/docs/images/pycharm.png +0 -0
  75. itables-2.2.5/docs/pandas_style.md +0 -100
  76. itables-2.2.5/docs/polars_dataframes.md +0 -172
  77. itables-2.2.5/docs/quarto/quarto_html.qmd +0 -134
  78. itables-2.2.5/docs/quarto/quarto_revealjs.qmd +0 -134
  79. itables-2.2.5/docs/quarto.md +0 -17
  80. itables-2.2.5/docs/quick_start.md +0 -103
  81. itables-2.2.5/docs/references.md +0 -19
  82. itables-2.2.5/docs/sample_dataframes.md +0 -183
  83. itables-2.2.5/docs/select.md +0 -84
  84. itables-2.2.5/docs/shiny.md +0 -128
  85. itables-2.2.5/docs/show_df.png +0 -0
  86. itables-2.2.5/docs/streamlit.md +0 -51
  87. itables-2.2.5/docs/supported_editors.md +0 -50
  88. itables-2.2.5/docs/troubleshooting.md +0 -64
  89. itables-2.2.5/docs/widget.md +0 -124
  90. itables-2.2.5/environment.yml +0 -30
  91. itables-2.2.5/packages/dt_for_itables/CHANGELOG.md +0 -31
  92. itables-2.2.5/packages/dt_for_itables/LICENSE +0 -21
  93. itables-2.2.5/packages/dt_for_itables/README.md +0 -32
  94. itables-2.2.5/packages/dt_for_itables/package-lock.json +0 -722
  95. itables-2.2.5/packages/dt_for_itables/package.json +0 -48
  96. itables-2.2.5/packages/dt_for_itables/src/index.css +0 -8
  97. itables-2.2.5/packages/dt_for_itables/src/index.d.ts +0 -1
  98. itables-2.2.5/packages/dt_for_itables/src/index.js +0 -59
  99. itables-2.2.5/packages/itables_anywidget/README.md +0 -29
  100. itables-2.2.5/packages/itables_anywidget/js/widget.css +0 -0
  101. itables-2.2.5/packages/itables_anywidget/js/widget.ts +0 -103
  102. itables-2.2.5/packages/itables_anywidget/package-lock.json +0 -485
  103. itables-2.2.5/packages/itables_anywidget/package.json +0 -15
  104. itables-2.2.5/packages/itables_anywidget/tsconfig.json +0 -25
  105. itables-2.2.5/packages/itables_for_streamlit/README.md +0 -9
  106. itables-2.2.5/packages/itables_for_streamlit/package-lock.json +0 -18075
  107. itables-2.2.5/packages/itables_for_streamlit/package.json +0 -39
  108. itables-2.2.5/packages/itables_for_streamlit/public/index.html +0 -12
  109. itables-2.2.5/packages/itables_for_streamlit/src/index.tsx +0 -58
  110. itables-2.2.5/packages/itables_for_streamlit/tsconfig.json +0 -19
  111. itables-2.2.5/packages/package-lock.json +0 -10
  112. itables-2.2.5/packages/package.json +0 -11
  113. itables-2.2.5/src/itables/__init__.py +0 -17
  114. itables-2.2.5/src/itables/datatables_format.py +0 -146
  115. itables-2.2.5/src/itables/html/column_filters/initComplete.js +0 -14
  116. itables-2.2.5/src/itables/html/column_filters/pre_dt_code.js +0 -8
  117. itables-2.2.5/src/itables/html/datatables_template.html +0 -20
  118. itables-2.2.5/src/itables/html/dt_bundle.css +0 -1
  119. itables-2.2.5/src/itables/html/dt_bundle.js +0 -144
  120. itables-2.2.5/src/itables/html/init_datatables.html +0 -25
  121. itables-2.2.5/src/itables/itables_for_streamlit/asset-manifest.json +0 -13
  122. itables-2.2.5/src/itables/itables_for_streamlit/static/css/main.b5025928.css +0 -2
  123. itables-2.2.5/src/itables/itables_for_streamlit/static/css/main.b5025928.css.map +0 -1
  124. itables-2.2.5/src/itables/itables_for_streamlit/static/js/main.f651d116.js +0 -3
  125. itables-2.2.5/src/itables/itables_for_streamlit/static/js/main.f651d116.js.map +0 -1
  126. itables-2.2.5/src/itables/javascript.py +0 -979
  127. itables-2.2.5/src/itables/options.py +0 -75
  128. itables-2.2.5/src/itables/streamlit.py +0 -13
  129. itables-2.2.5/src/itables/widget/__init__.py +0 -121
  130. itables-2.2.5/src/itables/widget/static/widget.css +0 -1
  131. itables-2.2.5/src/itables/widget/static/widget.js +0 -144
  132. itables-2.2.5/tests/__init__.py +0 -0
  133. itables-2.2.5/tests/conftest.py +0 -31
  134. itables-2.2.5/tests/test_changelog.py +0 -37
  135. itables-2.2.5/tests/test_connected_notebook_is_small.py +0 -39
  136. itables-2.2.5/tests/test_datatables_format.py +0 -172
  137. itables-2.2.5/tests/test_documentation_notebooks_run.py +0 -48
  138. itables-2.2.5/tests/test_downsample.py +0 -126
  139. itables-2.2.5/tests/test_extension_arguments.py +0 -68
  140. itables-2.2.5/tests/test_html_in_table_header.py +0 -9
  141. itables-2.2.5/tests/test_init.py +0 -17
  142. itables-2.2.5/tests/test_javascript.py +0 -126
  143. itables-2.2.5/tests/test_json_dumps.py +0 -74
  144. itables-2.2.5/tests/test_notebook.ipynb +0 -124
  145. itables-2.2.5/tests/test_pandas_style.py +0 -36
  146. itables-2.2.5/tests/test_polars.py +0 -40
  147. itables-2.2.5/tests/test_sample_dfs.py +0 -129
  148. itables-2.2.5/tests/test_shiny.py +0 -29
  149. itables-2.2.5/tests/test_update_samples.py +0 -31
  150. {itables-2.2.5 → itables-2.4.0rc0}/LICENSE +0 -0
  151. {itables-2.2.5/src → itables-2.4.0rc0}/itables/logo/loading.svg +0 -0
  152. {itables-2.2.5/src → itables-2.4.0rc0}/itables/logo/logo.svg +0 -0
  153. {itables-2.2.5/src → itables-2.4.0rc0}/itables/logo/text.svg +0 -0
  154. {itables-2.2.5/src → itables-2.4.0rc0}/itables/logo/wide.svg +0 -0
  155. {itables-2.2.5/src → itables-2.4.0rc0}/itables/logo/with_text.svg +0 -0
  156. {itables-2.2.5/src → itables-2.4.0rc0}/itables/samples/countries.csv +0 -0
  157. {itables-2.2.5/src → itables-2.4.0rc0}/itables/samples/indicators.csv +0 -0
  158. {itables-2.2.5/src → itables-2.4.0rc0}/itables/samples/population.csv +0 -0
@@ -28,7 +28,11 @@ node_modules
28
28
  dt_bundle.js
29
29
  dt_bundle.css
30
30
 
31
- # Streamlit package
31
+ # Dash component
32
+ src/itables_for_dash/*.js*
33
+ src/itables_for_dash/_imports_.py
34
+
35
+ # Streamlit component
32
36
  src/itables/itables_for_streamlit
33
37
 
34
38
  # Jupyter Widget
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: itables
3
- Version: 2.2.5
3
+ Version: 2.4.0rc0
4
4
  Summary: Pandas and Polar DataFrames as interactive DataTables
5
5
  Project-URL: Homepage, https://mwouts.github.io/itables/
6
6
  Project-URL: Documentation, https://mwouts.github.io/itables
@@ -39,14 +39,12 @@ Classifier: Intended Audience :: Science/Research
39
39
  Classifier: License :: OSI Approved :: MIT License
40
40
  Classifier: Programming Language :: Python
41
41
  Classifier: Programming Language :: Python :: 3
42
- Classifier: Programming Language :: Python :: 3.7
43
- Classifier: Programming Language :: Python :: 3.8
44
42
  Classifier: Programming Language :: Python :: 3.9
45
43
  Classifier: Programming Language :: Python :: 3.10
46
44
  Classifier: Programming Language :: Python :: 3.11
47
45
  Classifier: Programming Language :: Python :: 3.12
48
46
  Classifier: Programming Language :: Python :: 3.13
49
- Requires-Python: >=3.7
47
+ Requires-Python: >=3.9
50
48
  Requires-Dist: ipython
51
49
  Requires-Dist: numpy
52
50
  Requires-Dist: pandas
@@ -57,9 +55,13 @@ Requires-Dist: polars; extra == 'all'
57
55
  Requires-Dist: pyarrow; extra == 'all'
58
56
  Requires-Dist: pytz; extra == 'all'
59
57
  Requires-Dist: traitlets; extra == 'all'
58
+ Requires-Dist: typeguard>=4.4.1; extra == 'all'
60
59
  Requires-Dist: world-bank-data; extra == 'all'
60
+ Provides-Extra: check-type
61
+ Requires-Dist: typeguard>=4.4.1; extra == 'check-type'
61
62
  Provides-Extra: dev
62
63
  Requires-Dist: anywidget; extra == 'dev'
64
+ Requires-Dist: dash; extra == 'dev'
63
65
  Requires-Dist: ipykernel; extra == 'dev'
64
66
  Requires-Dist: jupyterlab; extra == 'dev'
65
67
  Requires-Dist: jupytext; extra == 'dev'
@@ -73,6 +75,7 @@ Requires-Dist: pytz; extra == 'dev'
73
75
  Requires-Dist: requests; extra == 'dev'
74
76
  Requires-Dist: shiny; extra == 'dev'
75
77
  Requires-Dist: traitlets; extra == 'dev'
78
+ Requires-Dist: typeguard>=4.4.1; extra == 'dev'
76
79
  Requires-Dist: watchfiles; extra == 'dev'
77
80
  Requires-Dist: world-bank-data; extra == 'dev'
78
81
  Provides-Extra: polars
@@ -85,6 +88,7 @@ Provides-Extra: style
85
88
  Requires-Dist: matplotlib; extra == 'style'
86
89
  Provides-Extra: test
87
90
  Requires-Dist: anywidget; extra == 'test'
91
+ Requires-Dist: dash; extra == 'test'
88
92
  Requires-Dist: ipykernel; extra == 'test'
89
93
  Requires-Dist: jupytext; extra == 'test'
90
94
  Requires-Dist: matplotlib; extra == 'test'
@@ -97,6 +101,7 @@ Requires-Dist: pytz; extra == 'test'
97
101
  Requires-Dist: requests; extra == 'test'
98
102
  Requires-Dist: shiny; extra == 'test'
99
103
  Requires-Dist: traitlets; extra == 'test'
104
+ Requires-Dist: typeguard>=4.4.1; extra == 'test'
100
105
  Requires-Dist: world-bank-data; extra == 'test'
101
106
  Provides-Extra: widget
102
107
  Requires-Dist: anywidget; extra == 'widget'
@@ -112,10 +117,11 @@ Description-Content-Type: text/markdown
112
117
  [![Conda Version](https://img.shields.io/conda/vn/conda-forge/itables.svg)](https://anaconda.org/conda-forge/itables)
113
118
  [![pyversions](https://img.shields.io/pypi/pyversions/itables.svg)](https://pypi.python.org/pypi/itables)
114
119
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
115
- [![Jupyter Widget](https://img.shields.io/badge/Jupyter-Widget-F37626.svg?style=flat&logo=Jupyter)](https://mwouts.github.io/itables/widget.html)
120
+ [![Jupyter Widget](https://img.shields.io/badge/Jupyter-Widget-F37626.svg?style=flat&logo=Jupyter)](https://mwouts.github.io/itables/apps/widget.html)
121
+ [![Dash Component](https://img.shields.io/badge/Dash-Plotly-1098F7.svg?style=flat&logo=Plotly)](https://mwouts.github.io/itables/apps/dash.html)
116
122
  [![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_red.svg)](https://itables.streamlit.app)
117
123
 
118
- This packages changes how Pandas and Polars DataFrames are rendered in Jupyter Notebooks.
124
+ This packages changes how Pandas and Polars DataFrames are rendered in Python notebooks and applications.
119
125
  With `itables` you can display your tables as interactive [DataTables](https://datatables.net/)
120
126
  that you can sort, paginate, scroll or filter.
121
127
 
@@ -143,26 +149,20 @@ or
143
149
  conda install itables -c conda-forge
144
150
  ```
145
151
 
146
- Activate the interactive mode for all series and dataframes with
152
+ Activate the interactive mode for all series and dataframes in Jupyter with
147
153
  ```python
148
- from itables import init_notebook_mode
154
+ import itables
149
155
 
150
- init_notebook_mode(all_interactive=True)
156
+ itables.init_notebook_mode()
151
157
  ```
152
158
  and then render any DataFrame as an interactive table that you can sort, search and explore:
153
159
  ![df](docs/df_example.png)
154
160
 
155
- If you prefer to render only selected DataFrames as interactive tables, use `itables.show` to show just one Series or DataFrame as an interactive table:
161
+ If you prefer to render only selected DataFrames as interactive tables, call `itables.init_notebook_mode(all_interactive=False)`, then use `itables.show` to show just one Series or DataFrame as an interactive table:
156
162
  ![show](docs/show_df.png)
157
163
 
158
- Since ITables v1.0, the [jQuery](https://jquery.com/) and [DataTables](https://datatables.net/) libraries and CSS
159
- are injected in the notebook when you execute `init_notebook_mode` with its default argument `connected=False`.
160
- Thanks to this the interactive tables will work even without a connection to the internet.
161
164
 
162
- If you prefer to load the libraries dynamically (and keep the notebook lighter), use `connected=True` when you
163
- execute `init_notebook_mode`.
164
-
165
- ## Supported environments
165
+ ## ITables in Notebooks
166
166
 
167
167
  ITables works in all the usual Jupyter Notebook environments, including Jupyter Notebook, Jupyter Lab, Jupyter nbconvert (i.e. the tables are still interactive in the HTML export of a notebook), Jupyter Book, Google Colab and Kaggle.
168
168
 
@@ -170,7 +170,18 @@ You can also use ITables in [Quarto](https://mwouts.github.io/itables/quarto.htm
170
170
 
171
171
  ITables works well in VS Code, both in Jupyter Notebooks and in interactive Python sessions.
172
172
 
173
- Last but not least, ITables is also available as
173
+ ## ITables in Python applications
174
+
175
+ ITables is also available as
174
176
  - a [Jupyter Widget](https://mwouts.github.io/itables/widget.html)
177
+ - a [Dash](https://mwouts.github.io/itables/dash.html) component
175
178
  - a [Streamlit](https://mwouts.github.io/itables/streamlit.html) component,
176
179
  - and it also works in [Shiny](https://mwouts.github.io/itables/shiny.html) applications.
180
+
181
+ ## Licence
182
+
183
+ ITables is developed by [Marc Wouts](https://github.com/mwouts) on [GitHub](https://github.com/mwouts/itables),
184
+ under a MIT license.
185
+
186
+ ITables is a wrapper for [datatables.net](https://datatables.net/) which is developed by Allan Jardine
187
+ [(sponsor him!)](https://github.com/sponsors/AllanJard), also under a MIT license.
@@ -7,10 +7,11 @@
7
7
  [![Conda Version](https://img.shields.io/conda/vn/conda-forge/itables.svg)](https://anaconda.org/conda-forge/itables)
8
8
  [![pyversions](https://img.shields.io/pypi/pyversions/itables.svg)](https://pypi.python.org/pypi/itables)
9
9
  [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
10
- [![Jupyter Widget](https://img.shields.io/badge/Jupyter-Widget-F37626.svg?style=flat&logo=Jupyter)](https://mwouts.github.io/itables/widget.html)
10
+ [![Jupyter Widget](https://img.shields.io/badge/Jupyter-Widget-F37626.svg?style=flat&logo=Jupyter)](https://mwouts.github.io/itables/apps/widget.html)
11
+ [![Dash Component](https://img.shields.io/badge/Dash-Plotly-1098F7.svg?style=flat&logo=Plotly)](https://mwouts.github.io/itables/apps/dash.html)
11
12
  [![Streamlit App](https://static.streamlit.io/badges/streamlit_badge_black_red.svg)](https://itables.streamlit.app)
12
13
 
13
- This packages changes how Pandas and Polars DataFrames are rendered in Jupyter Notebooks.
14
+ This packages changes how Pandas and Polars DataFrames are rendered in Python notebooks and applications.
14
15
  With `itables` you can display your tables as interactive [DataTables](https://datatables.net/)
15
16
  that you can sort, paginate, scroll or filter.
16
17
 
@@ -38,26 +39,20 @@ or
38
39
  conda install itables -c conda-forge
39
40
  ```
40
41
 
41
- Activate the interactive mode for all series and dataframes with
42
+ Activate the interactive mode for all series and dataframes in Jupyter with
42
43
  ```python
43
- from itables import init_notebook_mode
44
+ import itables
44
45
 
45
- init_notebook_mode(all_interactive=True)
46
+ itables.init_notebook_mode()
46
47
  ```
47
48
  and then render any DataFrame as an interactive table that you can sort, search and explore:
48
49
  ![df](docs/df_example.png)
49
50
 
50
- If you prefer to render only selected DataFrames as interactive tables, use `itables.show` to show just one Series or DataFrame as an interactive table:
51
+ If you prefer to render only selected DataFrames as interactive tables, call `itables.init_notebook_mode(all_interactive=False)`, then use `itables.show` to show just one Series or DataFrame as an interactive table:
51
52
  ![show](docs/show_df.png)
52
53
 
53
- Since ITables v1.0, the [jQuery](https://jquery.com/) and [DataTables](https://datatables.net/) libraries and CSS
54
- are injected in the notebook when you execute `init_notebook_mode` with its default argument `connected=False`.
55
- Thanks to this the interactive tables will work even without a connection to the internet.
56
54
 
57
- If you prefer to load the libraries dynamically (and keep the notebook lighter), use `connected=True` when you
58
- execute `init_notebook_mode`.
59
-
60
- ## Supported environments
55
+ ## ITables in Notebooks
61
56
 
62
57
  ITables works in all the usual Jupyter Notebook environments, including Jupyter Notebook, Jupyter Lab, Jupyter nbconvert (i.e. the tables are still interactive in the HTML export of a notebook), Jupyter Book, Google Colab and Kaggle.
63
58
 
@@ -65,7 +60,18 @@ You can also use ITables in [Quarto](https://mwouts.github.io/itables/quarto.htm
65
60
 
66
61
  ITables works well in VS Code, both in Jupyter Notebooks and in interactive Python sessions.
67
62
 
68
- Last but not least, ITables is also available as
63
+ ## ITables in Python applications
64
+
65
+ ITables is also available as
69
66
  - a [Jupyter Widget](https://mwouts.github.io/itables/widget.html)
67
+ - a [Dash](https://mwouts.github.io/itables/dash.html) component
70
68
  - a [Streamlit](https://mwouts.github.io/itables/streamlit.html) component,
71
69
  - and it also works in [Shiny](https://mwouts.github.io/itables/shiny.html) applications.
70
+
71
+ ## Licence
72
+
73
+ ITables is developed by [Marc Wouts](https://github.com/mwouts) on [GitHub](https://github.com/mwouts/itables),
74
+ under a MIT license.
75
+
76
+ ITables is a wrapper for [datatables.net](https://datatables.net/) which is developed by Allan Jardine
77
+ [(sponsor him!)](https://github.com/sponsors/AllanJard), also under a MIT license.
@@ -0,0 +1,18 @@
1
+ from itables import downsample, options, sample_dfs, widget
2
+
3
+ from .javascript import init_notebook_mode, show, to_html_datatable
4
+ from .typing import JavascriptCode, JavascriptFunction
5
+ from .version import __version__
6
+
7
+ __all__ = [
8
+ "__version__",
9
+ "to_html_datatable",
10
+ "show",
11
+ "init_notebook_mode",
12
+ "JavascriptCode",
13
+ "JavascriptFunction",
14
+ "options",
15
+ "downsample",
16
+ "sample_dfs",
17
+ "widget",
18
+ ]
@@ -0,0 +1,15 @@
1
+ from itables import __version__
2
+ from itables_for_dash import (
3
+ ITABLE_PROPERTIES,
4
+ ITable,
5
+ ITableOutputs,
6
+ updated_itable_outputs,
7
+ )
8
+
9
+ __all__ = [
10
+ "ITable",
11
+ "ITABLE_PROPERTIES",
12
+ "ITableOutputs",
13
+ "updated_itable_outputs",
14
+ "__version__",
15
+ ]
@@ -0,0 +1,147 @@
1
+ import json
2
+ import warnings
3
+ from typing import Optional
4
+
5
+ import numpy as np
6
+ import pandas as pd
7
+ import pandas.io.formats.format as fmt
8
+
9
+ try:
10
+ import polars as pl
11
+ except ImportError:
12
+ pl = None
13
+
14
+
15
+ def _format_column(x, escape_html: bool):
16
+ dtype_kind = x.dtype.kind
17
+ if dtype_kind in ["b", "i"]:
18
+ return x
19
+
20
+ if dtype_kind == "s":
21
+ if escape_html:
22
+ return x
23
+ return [escape_html_chars(i) for i in x]
24
+
25
+ try:
26
+ x = fmt.format_array(x._values, None, justify="all", leading_space=False) # type: ignore
27
+ except TypeError:
28
+ # Older versions of Pandas don't have 'leading_space'
29
+ x = fmt.format_array(x._values, None, justify="all") # type: ignore
30
+
31
+ if dtype_kind == "f":
32
+ try:
33
+ x = np.array(x).astype(float)
34
+ except ValueError:
35
+ pass
36
+
37
+ x = [escape_non_finite_float(f) for f in x]
38
+
39
+ if escape_html:
40
+ return [escape_html_chars(i) for i in x]
41
+
42
+ return x
43
+
44
+
45
+ def escape_non_finite_float(value):
46
+ """Encode non-finite float values to strings that will be parsed by parseJSON"""
47
+ if not isinstance(value, float):
48
+ return value
49
+ if np.isnan(value):
50
+ return "___NaN___"
51
+ if value == np.inf:
52
+ return "___Infinity___"
53
+ if value == -np.inf:
54
+ return "___-Infinity___"
55
+ return value
56
+
57
+
58
+ def escape_html_chars(value):
59
+ """Escape HTML special characters"""
60
+ if isinstance(value, str):
61
+ from pandas.io.formats.printing import pprint_thing # type: ignore
62
+
63
+ return pprint_thing(
64
+ value, escape_chars={"&": r"&amp;", "<": r"&lt;", ">": r"&gt;"}
65
+ ).strip()
66
+ return value
67
+
68
+
69
+ def generate_encoder(warn_on_unexpected_types=True):
70
+ class TableValuesEncoder(json.JSONEncoder):
71
+ def default(self, o):
72
+ if isinstance(o, (bool, int, float, str)):
73
+ return json.JSONEncoder.default(self, o)
74
+ if isinstance(o, np.bool_):
75
+ return bool(o)
76
+ if isinstance(o, np.integer):
77
+ return int(o)
78
+ if isinstance(o, np.floating):
79
+ return float(o)
80
+ try:
81
+ if o is pd.NA:
82
+ return str(o)
83
+ except AttributeError:
84
+ pass
85
+
86
+ if warn_on_unexpected_types:
87
+ warnings.warn(
88
+ f"Unexpected type '{type(o)}' for '{o}'.\n"
89
+ "You can report this warning at https://github.com/mwouts/itables/issues\n"
90
+ "To silence this warning, please run:\n"
91
+ " itables.options.warn_on_unexpected_types = False",
92
+ category=RuntimeWarning,
93
+ )
94
+ return str(o)
95
+
96
+ return TableValuesEncoder
97
+
98
+
99
+ def _isetitem(df, i, value):
100
+ """Older versions of Pandas don't have df.isetitem"""
101
+ try:
102
+ df.isetitem(i, value)
103
+ except AttributeError:
104
+ df.iloc[:, i] = value
105
+
106
+
107
+ def datatables_rows(
108
+ df,
109
+ column_count: Optional[int] = None,
110
+ warn_on_unexpected_types: bool = False,
111
+ escape_html: bool = True,
112
+ ):
113
+ """Format the values in the table and return the data, row by row, as requested by DataTables"""
114
+ # We iterate over columns using an index rather than the column name
115
+ # to avoid an issue in case of duplicated column names #89
116
+ if column_count is None or len(df.columns) == column_count:
117
+ empty_columns = []
118
+ else:
119
+ # When the header requires more columns (#141), we append empty columns on the left
120
+ missing_columns = column_count - len(df.columns)
121
+ assert missing_columns > 0
122
+ empty_columns = [[None] * len(df)] * missing_columns
123
+
124
+ try:
125
+ # Pandas DataFrame
126
+ data = list(
127
+ zip(
128
+ *(
129
+ empty_columns
130
+ + [_format_column(x, escape_html) for _, x in df.items()]
131
+ )
132
+ )
133
+ )
134
+ return json.dumps(
135
+ data,
136
+ cls=generate_encoder(warn_on_unexpected_types),
137
+ allow_nan=False,
138
+ )
139
+ except AttributeError:
140
+ # Polars DataFrame
141
+ data = df.rows()
142
+ data = [[escape_non_finite_float(f) for f in row] for row in data]
143
+
144
+ if escape_html:
145
+ data = [[escape_html_chars(i) for i in row] for row in data]
146
+
147
+ return json.dumps(data, cls=generate_encoder(False), allow_nan=False)
@@ -1,9 +1,8 @@
1
1
  import math
2
+ from typing import Union
2
3
 
3
4
  import pandas as pd
4
5
 
5
- from .datatables_format import _isetitem
6
-
7
6
 
8
7
  def nbytes(df):
9
8
  try:
@@ -31,7 +30,9 @@ def as_nbytes(mem):
31
30
  return int(float(mem))
32
31
 
33
32
 
34
- def downsample(df, max_rows=0, max_columns=0, max_bytes=0):
33
+ def downsample(
34
+ df, max_rows: int = 0, max_columns: int = 0, max_bytes: Union[int, str] = 0
35
+ ):
35
36
  """Return a subset of the dataframe that fits the limits"""
36
37
  org_rows, org_columns, org_bytes = len(df), len(df.columns), nbytes(df)
37
38
  max_bytes_numeric = as_nbytes(max_bytes)
@@ -113,16 +114,16 @@ def _downsample(df, max_rows=0, max_columns=0, max_bytes=0, target_aspect_ratio=
113
114
  first_half = max_columns - second_half
114
115
  assert first_half >= second_half
115
116
  if second_half:
116
- try:
117
+ if isinstance(df, pd.DataFrame):
117
118
  df = pd.concat(
118
119
  (df.iloc[:, :first_half], df.iloc[:, -second_half:]), axis=1
119
120
  )
120
- except AttributeError:
121
+ else:
121
122
  df = df[df.columns[:first_half]].hstack(df[df.columns[-second_half:]])
122
123
  else:
123
- try:
124
+ if isinstance(df, pd.DataFrame):
124
125
  df = df.iloc[:, :first_half]
125
- except AttributeError:
126
+ else:
126
127
  df = df[df.columns[:first_half]]
127
128
 
128
129
  df_nbytes = nbytes(df)
@@ -146,12 +147,14 @@ def _downsample(df, max_rows=0, max_columns=0, max_bytes=0, target_aspect_ratio=
146
147
  )
147
148
 
148
149
  # max_bytes is smaller than the average size of one cell
149
- try:
150
- df = df.iloc[:1, :1]
151
- _isetitem(df, 0, ["..."])
152
- except AttributeError:
150
+ if isinstance(df, pd.DataFrame):
151
+ return pd.DataFrame("...", index=df.index[:1], columns=df.columns[:1])
152
+
153
+ else:
153
154
  import polars as pl # noqa
154
155
 
156
+ assert isinstance(df, pl.DataFrame)
157
+
155
158
  df = pl.DataFrame({df.columns[0]: ["..."]})
156
159
  return df
157
160
 
@@ -0,0 +1,14 @@
1
+ <!--| quarto-html-table-processing: none -->
2
+ <table id="table_id"></table>
3
+ <link href="https://www.unpkg.com/dt_for_itables/dt_bundle.css" rel="stylesheet">
4
+ <script type="module">
5
+ import { ITable, jQuery as $ } from 'https://www.unpkg.com/dt_for_itables/dt_bundle.js';
6
+
7
+ document.querySelectorAll("#table_id:not(.dataTable)").forEach(table => {
8
+ if (!(table instanceof HTMLTableElement))
9
+ return;
10
+
11
+ let dt_args = {};
12
+ new ITable(table, dt_args);
13
+ });
14
+ </script>