-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lengthMenu can be either a 1D or 2D array (#153)
* update the csv file only if it is missing * passing an option with value=None is not allowed * fix set dom=t when the table fits on one page * Version 1.4.5
- Loading branch information
Showing
7 changed files
with
132 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
"""ITables' version number""" | ||
|
||
__version__ = "1.4.4" | ||
__version__ = "1.4.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from itables.sample_dfs import get_dict_of_test_dfs | ||
|
||
|
||
@pytest.fixture(params=list(get_dict_of_test_dfs())) | ||
def df(request): | ||
name = request.param | ||
df = get_dict_of_test_dfs()[name] | ||
assert isinstance(df, pd.DataFrame) | ||
return df | ||
|
||
|
||
@pytest.fixture(params=["None", "1D-array", "2D-array"]) | ||
def lengthMenu(request): | ||
if request.param == "None": | ||
return None | ||
if request.param == "1D-array": | ||
return [2, 5, 10, 20, 50] | ||
if request.param == "2D-array": | ||
return [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]] | ||
raise KeyError(request.param) | ||
|
||
|
||
@pytest.fixture(params=["None", "lfrtip"]) | ||
def dom(request): | ||
if request.param == "None": | ||
return None | ||
return request.param |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
import pandas as pd | ||
import pytest | ||
|
||
from itables.javascript import to_html_datatable | ||
|
||
|
||
@pytest.fixture() | ||
def df(): | ||
return pd.DataFrame([1, 2]) | ||
from itables.javascript import ( | ||
_set_dom_equals_t_if_df_fits_in_one_page, | ||
to_html_datatable, | ||
) | ||
|
||
|
||
def test_warn_on_unexpected_types_not_in_html(df): | ||
html = to_html_datatable(df) | ||
assert "warn_on_unexpected_types" not in html | ||
|
||
|
||
def test_set_dom_equals_t_if_df_fits_in_one_page(df, dom, lengthMenu): | ||
kwargs = dict(lengthMenu=lengthMenu, dom=dom) | ||
kwargs = {key: value for key, value in kwargs.items() if value is not None} | ||
_set_dom_equals_t_if_df_fits_in_one_page(df, kwargs) | ||
|
||
if dom is not None: | ||
assert kwargs["dom"] == dom | ||
return | ||
|
||
if lengthMenu is None: | ||
if len(df) <= 10: | ||
assert kwargs["dom"] == "t" | ||
return | ||
|
||
assert "dom" not in kwargs | ||
return | ||
|
||
min_rows = lengthMenu[0] | ||
if isinstance(min_rows, list): | ||
min_rows = min_rows[0] | ||
|
||
if len(df) <= min_rows: | ||
assert kwargs["dom"] == "t" | ||
return | ||
|
||
assert "dom" not in kwargs | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
import world_bank_data as wb | ||
|
||
sample_dir = Path(__file__).parent / ".." / "itables" / "samples" | ||
SAMPLE_DIR = Path(__file__).parent / ".." / "itables" / "samples" | ||
|
||
|
||
def test_update_countries(): | ||
def create_csv_file_if_missing(df, csv_file): | ||
if not csv_file.exists(): | ||
with open(str(csv_file), "w") as fp: | ||
fp.write(df.to_csv()) | ||
|
||
|
||
def test_update_countries(csv_file=SAMPLE_DIR / "countries.csv"): | ||
df = wb.get_countries() | ||
with open(str(sample_dir / "countries.csv"), "w") as fp: | ||
fp.write(df.to_csv()) | ||
create_csv_file_if_missing(df, csv_file) | ||
|
||
|
||
def test_update_population(): | ||
def test_update_population(csv_file=SAMPLE_DIR / "population.csv"): | ||
x = wb.get_series("SP.POP.TOTL", mrv=1, simplify_index=True) | ||
with open(str(sample_dir / "population.csv"), "w") as fp: | ||
fp.write(x.to_csv()) | ||
create_csv_file_if_missing(x, csv_file) | ||
|
||
|
||
@pytest.mark.skip("The indicators appear to change often") | ||
def test_update_indicators(): | ||
def test_update_indicators(csv_file=SAMPLE_DIR / "indicators.csv"): | ||
df = wb.get_indicators().sort_index().head(500) | ||
with open(str(sample_dir / "indicators.csv"), "w") as fp: | ||
fp.write(df.to_csv()) | ||
create_csv_file_if_missing(df, csv_file) |