Skip to content

Commit

Permalink
Version 1.6.4 (#221)
Browse files Browse the repository at this point in the history
* Fix complex table footers

* Address pytest.skip warning
pytest.PytestRemovedIn8Warning: pytest.skip(msg=...) is now deprecated, use pytest.skip(reason=...) instead

* Address pandas warning
FutureWarning: 'S' is deprecated and will be removed in a future version, please use 's' instead.

* Remove environment2.yml

* Adjust the tests for pandas=2.2.0
pandas-dev/pandas#57229
pandas-dev/pandas#55080
  • Loading branch information
mwouts committed Feb 3, 2024
1 parent a526158 commit 2b24efa
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 45 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2023 Marc Wouts
Copyright (c) 2019-2024 Marc Wouts

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 11 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
ITables ChangeLog
=================

1.6.4 (2024-02-03)
------------------

**Fixed**
- Complex table footers are now in the correct order ([#219](https://github.com/mwouts/itables/issues/219))
- We have adjusted the test suite for `pandas==2.2.0`
([#223](https://github.com/mwouts/itables/issues/223),
[pandas-57229](https://github.com/pandas-dev/pandas/issues/57229),
[pandas-55080](https://github.com/pandas-dev/pandas/issues/55080))


1.6.3 (2023-12-10)
------------------

Expand Down
17 changes: 0 additions & 17 deletions environment2.yml

This file was deleted.

42 changes: 26 additions & 16 deletions itables/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,6 @@ def _table_header(
if not show_index and len(df.columns):
thead = thead.replace("<th></th>", "", 1)

if column_filters:
# We use this header in the column filters, so we need to remove any column multiindex first"""
thead_flat = ""
if show_index:
for index in df.index.names:
thead_flat += "<th>{}</th>".format(index)

for column in df.columns:
thead_flat += "<th>{}</th>".format(column)

loading = "<td>Loading... (need <a href=https://mwouts.github.io/itables/troubleshooting.html>help</a>?)</td>"
tbody = "<tr>{}</tr>".format(loading)

Expand All @@ -172,15 +162,14 @@ def _table_header(
else:
style = ""

if column_filters == "header":
header = "<thead>{}</thead>".format(thead_flat)
else:
header = "<thead>{}</thead>".format(thead)
header = "<thead>{}</thead>".format(
_flat_header(df, show_index) if column_filters == "header" else thead
)

if column_filters == "footer":
footer = "<tfoot>{}</tfoot>".format(thead_flat)
footer = "<tfoot>{}</tfoot>".format(_flat_header(df, show_index))
elif footer:
footer = "<tfoot>{}</tfoot>".format(thead)
footer = "<tfoot>{}</tfoot>".format(_tfoot_from_thead(thead))
else:
footer = ""

Expand All @@ -195,6 +184,27 @@ def _table_header(
)


def _flat_header(df, show_index):
"""When column filters are shown, we need to remove any column multiindex"""
header = ""
if show_index:
for index in df.index.names:
header += "<th>{}</th>".format(index)

for column in df.columns:
header += "<th>{}</th>".format(column)

return header


def _tfoot_from_thead(thead):
header_rows = thead.split("</tr>")
last_row = header_rows[-1]
assert not last_row.strip(), last_row
header_rows = header_rows[:-1]
return "".join(row + "</tr>" for row in header_rows[::-1] if "<tr" in row) + "\n"


def json_dumps(obj, eval_functions):
"""
This is a replacement for json.dumps that
Expand Down
12 changes: 5 additions & 7 deletions itables/sample_dfs.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import math
import string
from datetime import datetime, timedelta

try:
from functools import lru_cache
except ImportError:
from functools32 import lru_cache

from functools import lru_cache
from itertools import cycle

import numpy as np
Expand Down Expand Up @@ -176,7 +171,7 @@ def get_dict_of_test_dfs(N=100, M=100, polars=False):
}
),
"date_range": pd.DataFrame(
{"timestamps": pd.date_range("now", periods=5, freq="S")}
{"timestamps": pd.date_range("now", periods=5, freq="s")}
),
"ordered_categories": pd.DataFrame(
{"int": np.arange(4)},
Expand Down Expand Up @@ -317,6 +312,9 @@ def get_dict_of_test_series(polars=False):

@lru_cache()
def generate_date_series():
if pd.__version__ >= "2.2.0":
# https://github.com/pandas-dev/pandas/issues/55080 is back in 2.2.0?
return pd.Series(pd.date_range("1970-01-01", "2099-12-31", freq="D"))
return pd.Series(pd.date_range("1677-09-23", "2262-04-10", freq="D"))


Expand Down
2 changes: 1 addition & 1 deletion itables/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""ITables' version number"""

__version__ = "1.6.3"
__version__ = "1.6.4"
4 changes: 2 additions & 2 deletions tests/test_documentation_notebooks_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def list_doc_notebooks():
)
def test_run_documentation_notebooks(notebook):
if "polars" in notebook.stem and pl is None:
pytest.skip(msg="Polars is not available")
pytest.skip("Polars is not available")
if "pandas_style" in notebook.stem and pd_style is None:
pytest.skip(msg="Pandas Style is not available")
pytest.skip("Pandas Style is not available")

nb = jupytext.read(notebook)
py_notebook = jupytext.writes(nb, "py:percent")
Expand Down
52 changes: 51 additions & 1 deletion tests/test_javascript.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import pytest

from itables.javascript import _df_fits_in_one_page, replace_value, to_html_datatable
from itables.javascript import (
_df_fits_in_one_page,
_tfoot_from_thead,
replace_value,
to_html_datatable,
)


def test_replace_value(
Expand Down Expand Up @@ -46,3 +51,48 @@ def test_df_fits_in_one_page(df, lengthMenu):
min_rows = min_rows[0]

assert _df_fits_in_one_page(df, kwargs) == (len(df) <= min_rows)


def test_tfoot_from_thead(
thead="""
<tr style="text-align: right;">
<th></th>
<th>region</th>
<th>country</th>
<th>capital</th>
<th>longitude</th>
<th>latitude</th>
<th>flag</th>
</tr>
<tr>
<th>code</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
""",
expected_tfoot="""
<tr>
<th>code</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>
<tr style="text-align: right;">
<th></th>
<th>region</th>
<th>country</th>
<th>capital</th>
<th>longitude</th>
<th>latitude</th>
<th>flag</th>
</tr>
""",
):
assert _tfoot_from_thead(thead) == expected_tfoot
4 changes: 4 additions & 0 deletions tests/test_sample_dfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
pytest.mark.filterwarnings("error"),
# Seen on the CI on Py38 and Py39
pytest.mark.filterwarnings("ignore::ResourceWarning"),
# TODO: https://github.com/mwouts/itables/issues/223
pytest.mark.filterwarnings(
"ignore:Setting an item of incompatible dtype is deprecated:FutureWarning"
),
]

if PANDAS_VERSION_MAJOR < 2:
Expand Down

0 comments on commit 2b24efa

Please sign in to comment.