Skip to content

Commit d1d366f

Browse files
authored
Version 1.1.0 (#81)
- `itables.options` and the `show` function have a new `column_filters` argument to display individual column search boxes ([#69](mwouts/jupytext#69)) - We have documented DataTables' `dom` option. - We have introduced a new class `JavascriptFunction` to limit the evaluation of Javascript function to selected ones. - The documentation is formatted with `black` thanks to a Jupytext & Black pre-commit hook.
1 parent 8f65693 commit d1d366f

17 files changed

+291
-107
lines changed

.pre-commit-config.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# Install pre-commit hooks via
22
# pre-commit install
33

4-
exclude: >
5-
(?x)^(
6-
\.vscode/settings\.json|
7-
demo/.*|
8-
index.html
9-
)$
104
repos:
115

126
- repo: https://github.com/pre-commit/pre-commit-hooks
@@ -38,3 +32,12 @@ repos:
3832
hooks:
3933
- id: pyupgrade
4034
args: ["--py36-plus"]
35+
36+
- repo: https://github.com/mwouts/jupytext
37+
rev: v1.13.8
38+
hooks:
39+
- id: jupytext
40+
types: ["markdown"]
41+
args: ["--pipe", "black"]
42+
additional_dependencies:
43+
- black==22.3.0 # Matches hook

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pip install itables
1616
Activate the interactive mode for all series and dataframes with
1717
```python
1818
from itables import init_notebook_mode
19+
1920
init_notebook_mode(all_interactive=True)
2021
```
2122
or use `itables.show` to show just one Series or DataFrame as an interactive table.

docs/advanced_parameters.md

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,62 @@ df
9696
You can set additional `tags` like a [caption](https://datatables.net/blog/2014-11-07) on the table with the `tags` option:
9797

9898
```{code-cell}
99-
show(df, tags='<caption>Countries from the World Bank Database</caption>')
99+
show(df, tags="<caption>Countries from the World Bank Database</caption>")
100100
```
101101

102102
The position of the caption can be set explicitly as in the datatables example above (note that the default position may depend on how you render the notebook):
103+
104+
```{code-cell}
105+
show(
106+
df,
107+
tags='<caption style="caption-side: top">Countries from the World Bank Database</caption>',
108+
)
109+
```
110+
111+
```{code-cell}
112+
opt.lengthMenu = [5, 10, 20, 50, 100, 200, 500]
113+
```
114+
115+
## Table footer
116+
117+
Use `footer = True` if you wish to display a table footer.
118+
119+
```{code-cell}
120+
show(df, footer=True)
121+
```
122+
123+
## Column filters
124+
125+
Use `column_filters = "header"` or `"footer"` if you wish to display individual column filters
126+
(remove the global search box with [`dom='lrtip'`](https://datatables.net/reference/option/dom) if desired).
127+
103128
```{code-cell}
104-
show(df, tags='<caption style="caption-side: top">Countries from the World Bank Database</caption>')
129+
alpha_numeric_df = pd.DataFrame(
130+
[["one", 1.5], ["two", 2.3]], columns=["string", "numeric"]
131+
)
132+
133+
show(alpha_numeric_df, column_filters="footer", dom="lrtip")
134+
```
135+
136+
As always you can set activate column filters by default with e.g.
137+
138+
```{code-cell}
139+
opt.column_filters = "footer"
140+
alpha_numeric_df
141+
```
142+
143+
Column filters also work on dataframes with multiindex columns:
144+
145+
```{code-cell}
146+
from itables.sample_dfs import get_dict_of_test_dfs
147+
148+
get_dict_of_test_dfs()["multiindex"]
149+
```
150+
151+
Now we deactivate the column filters for the rest of the notebook
152+
153+
```{code-cell}
154+
opt.column_filters = False
105155
```
106156

107157
## Float precision
@@ -129,22 +179,27 @@ You can use Javascript callbacks to set the cell or row style depending on the c
129179

130180
The example below, in which we color in red the cells with negative numbers, is directly inspired by the corresponding datatables.net [example](https://datatables.net/reference/option/columns.createdCell).
131181

182+
Note how the Javascript callback is declared as `JavascriptFunction` object below.
183+
132184
```{code-cell}
185+
from itables import JavascriptFunction
186+
133187
show(
134188
pd.DataFrame([[-1, 2, -3, 4, -5], [6, -7, 8, -9, 10]], columns=list("abcde")),
135189
columnDefs=[
136190
{
137191
"targets": "_all",
138-
"createdCell": """
192+
"createdCell": JavascriptFunction(
193+
"""
139194
function (td, cellData, rowData, row, col) {
140195
if (cellData < 0) {
141196
$(td).css('color', 'red')
142197
}
143198
}
144-
""",
199+
"""
200+
),
145201
}
146202
],
147-
eval_functions=True,
148203
)
149204
```
150205

@@ -214,7 +269,7 @@ show(
214269
The [search option](https://datatables.net/reference/option/search) let you control the initial value for the search field, and whether the query should be treated as a regular expression or not:
215270

216271
```{code-cell}
217-
show(df, search={"regex": True, "caseInsensitive": True, "search":"s.ain"})
272+
show(df, search={"regex": True, "caseInsensitive": True, "search": "s.ain"})
218273
```
219274

220275
## Select rows

docs/changelog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
ITables ChangeLog
22
=================
33

4+
1.1.0 (2022-06-23)
5+
------------------
6+
7+
**Added**
8+
- `itables.options` and the `show` function have a new `column_filters` argument to display individual column search boxes ([#69](https://github.com/mwouts/jupytext/issues/69))
9+
- We have introduced a new class `JavascriptFunction` to limit the evaluation of Javascript function to selected ones.
10+
- The documentation is formatted with `black` thanks to a Jupytext & Black pre-commit hook.
11+
12+
413
1.0.0 (2022-06-22)
514
------------------
615

docs/downsampling.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupytext:
55
extension: .md
66
format_name: myst
77
format_version: 0.13
8-
jupytext_version: 1.11.5
8+
jupytext_version: 1.13.8
99
kernelspec:
1010
display_name: itables
1111
language: python
@@ -20,13 +20,13 @@ When the data in a table is larger than `maxBytes`, which is equal to 64KB by de
2020

2121
If you wish, you can increase the value of `maxBytes` or even deactivate the limit (with `maxBytes=0`). Similarly you can set a limit on the number of rows (`maxRows`, defaults to 0) or columns (`maxColumns`, defaults to `pd.get_option('display.max_columns')`).
2222

23-
```{code-cell} ipython3
23+
```{code-cell}
2424
from itables import init_notebook_mode, show
2525
2626
init_notebook_mode(all_interactive=True)
2727
```
2828

29-
```{code-cell} ipython3
29+
```{code-cell}
3030
from itables.sample_dfs import get_indicators
3131
import itables.options as opt
3232
@@ -37,19 +37,19 @@ df = get_indicators()
3737
df.values.nbytes
3838
```
3939

40-
```{code-cell} ipython3
40+
```{code-cell}
4141
df
4242
```
4343

4444
To show the table in full, we can modify the value of `maxBytes` either locally:
4545

46-
```{code-cell} ipython3
46+
```{code-cell}
4747
show(df, maxBytes=0)
4848
```
4949

5050
or globally:
5151

52-
```{code-cell} ipython3
53-
opt.maxBytes = 2 ** 20
52+
```{code-cell}
53+
opt.maxBytes = 2**20
5454
df
5555
```

docs/quick_start.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupytext:
55
extension: .md
66
format_name: myst
77
format_version: 0.13
8-
jupytext_version: 1.11.5
8+
jupytext_version: 1.13.8
99
kernelspec:
1010
display_name: itables
1111
language: python
@@ -34,15 +34,15 @@ pip install itables
3434

3535
Activate the interactive mode for all series and dataframes with
3636

37-
```{code-cell} ipython3
37+
```{code-cell}
3838
from itables import init_notebook_mode
3939
4040
init_notebook_mode(all_interactive=True)
4141
```
4242

4343
After this, any Pandas object (DataFrame or Series) is displayed as an interactive [datatables.net](https://datatables.net/) table, which lets you explore, filter or sort your data.
4444

45-
```{code-cell} ipython3
45+
```{code-cell}
4646
from itables.sample_dfs import get_countries
4747
4848
df = get_countries()
@@ -51,7 +51,7 @@ df
5151

5252
If you prefer to render just one series or dataframe as an interactive table, use `show`:
5353

54-
```{code-cell} ipython3
54+
```{code-cell}
5555
from itables import show
5656
from itables.sample_dfs import get_population
5757

docs/sample_dataframes.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jupytext:
55
extension: .md
66
format_name: myst
77
format_version: 0.13
8-
jupytext_version: 1.11.5
8+
jupytext_version: 1.13.8
99
kernelspec:
1010
display_name: itables
1111
language: python
@@ -16,7 +16,7 @@ kernelspec:
1616

1717
In this notebook we make sure that our test dataframes are displayed nicely with the default `itables` settings.
1818

19-
```{code-cell} ipython3
19+
```{code-cell}
2020
from itables import init_notebook_mode, show
2121
from itables.sample_dfs import get_dict_of_test_dfs
2222
@@ -26,78 +26,78 @@ init_notebook_mode(all_interactive=True)
2626

2727
## empty
2828

29-
```{code-cell} ipython3
29+
```{code-cell}
3030
show(dict_of_test_dfs["empty"])
3131
```
3232

3333
## int
3434

35-
```{code-cell} ipython3
35+
```{code-cell}
3636
show(dict_of_test_dfs["int"])
3737
```
3838

3939
## float
4040

41-
```{code-cell} ipython3
41+
```{code-cell}
4242
show(dict_of_test_dfs["float"])
4343
```
4444

4545
## str
4646

47-
```{code-cell} ipython3
47+
```{code-cell}
4848
show(dict_of_test_dfs["str"])
4949
```
5050

5151
## time
5252

53-
```{code-cell} ipython3
53+
```{code-cell}
5454
show(dict_of_test_dfs["time"])
5555
```
5656

5757
## object
5858

59-
```{code-cell} ipython3
59+
```{code-cell}
6060
show(dict_of_test_dfs["object"])
6161
```
6262

6363
## multiindex
6464

65-
```{code-cell} ipython3
65+
```{code-cell}
6666
show(dict_of_test_dfs["multiindex"])
6767
```
6868

6969
## countries
7070

71-
```{code-cell} ipython3
71+
```{code-cell}
7272
show(dict_of_test_dfs["countries"])
7373
```
7474

7575
## capital
7676

77-
```{code-cell} ipython3
77+
```{code-cell}
7878
show(dict_of_test_dfs["capital"])
7979
```
8080

8181
## complex_index
8282

83-
```{code-cell} ipython3
83+
```{code-cell}
8484
show(dict_of_test_dfs["complex_index"])
8585
```
8686

8787
## int_float_str
8888

89-
```{code-cell} ipython3
89+
```{code-cell}
9090
show(dict_of_test_dfs["int_float_str"])
9191
```
9292

9393
## wide
9494

95-
```{code-cell} ipython3
95+
```{code-cell}
9696
show(dict_of_test_dfs["wide"], maxBytes=100000, maxColumns=100)
9797
```
9898

9999
## long_column_names
100100

101-
```{code-cell} ipython3
101+
```{code-cell}
102102
show(dict_of_test_dfs["long_column_names"])
103103
```

itables/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .javascript import init_notebook_mode, show
1+
from .javascript import JavascriptFunction, init_notebook_mode, show
22
from .version import __version__
33

4-
__all__ = ["__version__", "show", "init_notebook_mode"]
4+
__all__ = ["__version__", "show", "init_notebook_mode", "JavascriptFunction"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const initComplete = function () {
2+
// Apply the search
3+
this.api()
4+
.columns()
5+
.every(function () {
6+
const that = this;
7+
8+
$('input', this.header()).on('keyup change clear', function () {
9+
if (that.search() !== this.value) {
10+
that.search(this.value).draw();
11+
}
12+
});
13+
});
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Setup - add a text input to each header or footer cell
2+
$('#table_id thead_or_tfoot th').each(function () {
3+
let title = $(this).text();
4+
$(this).html('<input type="text" placeholder="Search ' +
5+
// We use encodeURI to avoid this LGTM error:
6+
// https://lgtm.com/rules/1511866576920/
7+
encodeURI(title).replaceAll("%20", " ") +
8+
'" />');
9+
});

0 commit comments

Comments
 (0)