Skip to content

Commit 2ad4f0c

Browse files
committed
Ignore showIndex when df is a Polars DataFrame
1 parent 8870083 commit 2ad4f0c

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

docs/changelog.md

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

4+
2.4.5 (2025-08-23)
5+
------------------
6+
7+
**Fixed**
8+
- The `showIndex` argument is now ignored when `df` is a Polars DataFrame ([#422](https://github.com/mwouts/itables/issues/422))
9+
- The dependencies of the streamlit component have been updated to address security issues ([#420](https://github.com/mwouts/itables/pull/420), [#421](https://github.com/mwouts/itables/pull/421), [#425](https://github.com/mwouts/itables/pull/425))
10+
11+
412
2.4.4 (2025-07-07)
513
------------------
614

src/itables/javascript.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,12 +347,12 @@ def _evaluate_show_index(df, showIndex) -> bool:
347347
"""
348348
We don't want to show trivial indices (RangeIndex with no name) on Pandas DataFrames.
349349
"""
350-
if showIndex != "auto":
351-
return showIndex
352350
if df is None:
353351
return False
354352
if pl is not pd and isinstance(df, pl.DataFrame):
355353
return False
354+
if showIndex != "auto":
355+
return showIndex
356356
if isinstance(df, pd.DataFrame):
357357
return df.index.name is not None or not isinstance(df.index, pd.RangeIndex)
358358
if pd_style is not None and isinstance(df, pd_style.Styler):

src/itables/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""ITables' version number"""
22

3-
__version__ = "2.4.4"
3+
__version__ = "2.4.5"

tests/test_polars.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from itables import to_html_datatable
4-
from itables.javascript import datatables_rows
4+
from itables.javascript import datatables_rows, get_itable_arguments
55
from itables.sample_dfs import (
66
get_dict_of_polars_test_dfs,
77
get_dict_of_polars_test_series,
@@ -53,3 +53,16 @@ def test_render_polars_struct():
5353
datatables_rows(df.select(pl.col("X").value_counts(sort=True)))
5454
== '[["{\\"C\\",3}"], ["{\\"A\\",2}"], ["{\\"B\\",1}"]]'
5555
)
56+
57+
58+
@pytest.mark.parametrize("show_index", ["auto", False, True])
59+
def test_show_index_has_no_effect_on_polars_dataframes(show_index):
60+
df = pl.DataFrame(
61+
{
62+
"A": [1, 2, 3],
63+
"B": [4, 5, 6],
64+
}
65+
)
66+
itable_args = get_itable_arguments(df, showIndex=show_index)
67+
assert "data_json" in itable_args, set(itable_args)
68+
assert itable_args["data_json"] == "[[1, 4], [2, 5], [3, 6]]"

0 commit comments

Comments
 (0)