Skip to content

Commit

Permalink
Test Ibis dataframes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Dec 26, 2024
1 parent 0e1f293 commit 52484a2
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 2 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ jobs:
numpy-version: '<2.0'
- python-version: "3.13"
pandas-version: pre
- python-version: "3.12"
modifiers: "modin"
- python-version: "3.13"
modifiers: "polars"
- python-version: "3.13"
modifiers: "ibis"
- python-version: "3.12"
modifiers: "modin"
- python-version: "3.13"
modifiers: "uninstall_narwhals"
- python-version: "3.13"
Expand Down Expand Up @@ -97,6 +99,10 @@ jobs:
if: matrix.modifiers == 'polars'
run: pip install polars

- name: Install ibis
if: matrix.modifiers == 'ibis'
run: pip install 'ibis-framework[duckdb]'

- name: Install modin
if: matrix.modifiers == 'modin'
run: pip install modin[all]
Expand Down
183 changes: 183 additions & 0 deletions docs/ibis_dataframes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
---
jupytext:
formats: md:myst
notebook_metadata_filter: -jupytext.text_representation.jupytext_version
text_representation:
extension: .md
format_name: myst
format_version: 0.13
kernelspec:
display_name: itables
language: python
name: itables
---

# Sample dataframes

In this notebook we make sure that our test [Ibis](https://ibis-project.org/) dataframes are displayed nicely with the default `itables` settings.

```{code-cell}
from itables import init_notebook_mode, show
from itables.sample_dfs import get_dict_of_test_ibis_dfs
dict_of_test_dfs = get_dict_of_test_ibis_dfs()
init_notebook_mode(all_interactive=True)
```

## empty

```{code-cell}
show(dict_of_test_dfs["empty"])
```

## No rows

```{code-cell}
show(dict_of_test_dfs["no_rows"])
```

## No rows one column

```{code-cell}
show(dict_of_test_dfs["no_rows_one_column"])
```

## No columns

```{code-cell}
show(dict_of_test_dfs["no_columns"])
```

## No columns one row

```{code-cell}
show(dict_of_test_dfs["no_columns_one_row"])
```

## bool

```{code-cell}
show(dict_of_test_dfs["bool"])
```

## Nullable boolean

```{code-cell}
show(dict_of_test_dfs["nullable_boolean"])
```

## int

```{code-cell}
show(dict_of_test_dfs["int"])
```

## Nullable integer

```{code-cell}
show(dict_of_test_dfs["nullable_int"])
```

## float

```{code-cell}
show(dict_of_test_dfs["float"])
```

## str

```{code-cell}
show(dict_of_test_dfs["str"])
```

## time

```{code-cell}
show(dict_of_test_dfs["time"])
```

## object

```{code-cell}
show(dict_of_test_dfs["object"])
```

## ordered_categories

```{code-cell}
show(dict_of_test_dfs["ordered_categories"])
```

## ordered_categories_in_multiindex

```{code-cell}
show(dict_of_test_dfs["ordered_categories_in_multiindex"])
```

## multiindex

```{code-cell}
show(dict_of_test_dfs["multiindex"])
```

## countries

```{code-cell}
:tags: [full-width]
show(dict_of_test_dfs["countries"])
```

## capital

```{code-cell}
show(dict_of_test_dfs["capital"])
```

## complex_index

```{code-cell}
:tags: [full-width]
show(dict_of_test_dfs["complex_index"])
```

## int_float_str

```{code-cell}
show(dict_of_test_dfs["int_float_str"])
```

## wide

```{code-cell}
:tags: [full-width]
show(dict_of_test_dfs["wide"], maxBytes=100000, maxColumns=100, scrollX=True)
```

## long_column_names

```{code-cell}
:tags: [full-width]
show(dict_of_test_dfs["long_column_names"], scrollX=True)
```

## duplicated_columns

```{code-cell}
show(dict_of_test_dfs["duplicated_columns"])
```

## named_column_index

```{code-cell}
show(dict_of_test_dfs["named_column_index"])
```

## big_integers

```{code-cell}
show(dict_of_test_dfs["big_integers"])
```
3 changes: 3 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ dependencies:
- polars
- pyarrow

# Ibis
- ibis-duckdb

# Modin
- modin-ray

Expand Down
24 changes: 24 additions & 0 deletions src/itables/sample_dfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,26 @@ def get_dict_of_test_polars_dfs(**kwargs):
return polars_dfs


def get_dict_of_test_ibis_dfs(**kwargs):

import ibis

ibis_dfs = {}

t = ibis.table(dict(one="string", two="float", three="int32"), name="my_data")
ibis_dfs["table"] = t

ibis_dfs["table_select"] = t.select("two", "one")

for key, df in get_dict_of_test_dfs(**kwargs).items():
try:
ibis_dfs[key] = ibis.memtable(df)
except (TypeError, ibis.common.exceptions.IbisInputError):
pass

return ibis_dfs


def get_dict_of_test_modin_dfs(**kwargs):

import modin.pandas as mpd
Expand Down Expand Up @@ -336,6 +356,10 @@ def get_dict_of_test_polars_series():
return polars_series


def get_dict_of_test_ibis_series():
return {name: value for name, value in get_dict_of_test_ibis_dfs().items()}


def get_dict_of_test_modin_series():
import modin.pandas as mpd

Expand Down
43 changes: 43 additions & 0 deletions tests/test_ibis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest

from itables import to_html_datatable
from itables.javascript import datatables_rows
from itables.sample_dfs import get_dict_of_test_ibis_dfs, get_dict_of_test_ibis_series

pl = pytest.importorskip("ibis")


@pytest.fixture(params=get_dict_of_test_ibis_dfs().items(), ids=lambda param: param[0])
def df(request):
return request.param[1]


@pytest.fixture(
params=get_dict_of_test_ibis_series().items(), ids=lambda param: param[0]
)
def x(request):
return request.param[1]


def test_show_ibis_series(x, use_to_html):
to_html_datatable(x, use_to_html)


def test_show_ibis_df(df, use_to_html):
to_html_datatable(df, use_to_html)


def test_encode_mixed_contents():
# Make sure that the bigint escape works for mixed content # 291
df = pl.DataFrame(
{
"bigint": [1666767918216000000],
"int": [1699300000000],
"float": [0.9510565400123596],
"neg": [-0.30901700258255005],
}
)
assert (
datatables_rows(df)
== '[[BigInt("1666767918216000000"), 1699300000000, 0.9510565400123596, -0.30901700258255005]]'
)

0 comments on commit 52484a2

Please sign in to comment.