-
-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the ibis histogram #5531
Draft
MarcSkovMadsen
wants to merge
14
commits into
main
Choose a base branch
from
fix/histogram
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Fix the ibis histogram #5531
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bac745e
fix ibis bokeh datetime axis
a053b00
refactor
27b40b4
fix
7976efc
fix
ad69245
found the fix
5e5c469
mature ibis fix and tests
deeea89
iteration on ibis duckdb RowID error
1419105
refactor and test ibis bokeh yaxis
MarcSkovMadsen ddaeb3d
refactor
MarcSkovMadsen 68cc21f
Merge branch 'fix/ibi-datetime-axis' into fix/ibis-duckdb-no-rowid
MarcSkovMadsen ba03e62
Merge branch 'master' of https://github.com/holoviz/holoviews into fi…
MarcSkovMadsen a344388
fixes the ibis histogram
MarcSkovMadsen ab4898c
wip
MarcSkovMadsen 4d0ef55
Merge branch 'master' of https://github.com/holoviz/holoviews into fi…
MarcSkovMadsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,22 +1,32 @@ | ||
import sqlite3 | ||
from unittest import SkipTest | ||
|
||
from tempfile import NamedTemporaryFile | ||
from unittest import SkipTest | ||
|
||
try: | ||
import ibis | ||
from ibis import sqlite | ||
except: | ||
raise SkipTest("Could not import ibis, skipping IbisInterface tests.") | ||
|
||
try: | ||
import duckdb | ||
except: | ||
raise SkipTest("Could not import duckdb, skipping IbisInterface tests.") | ||
|
||
from pathlib import Path | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import param | ||
import pytest | ||
from bokeh.models import axes as bokeh_axes | ||
from holoviews import render | ||
from holoviews.core.data import Dataset | ||
from holoviews.core.spaces import HoloMap | ||
from holoviews.core.data.ibis import IbisInterface | ||
from holoviews.core.spaces import HoloMap | ||
from holoviews.element.chart import Curve | ||
|
||
from .base import HeterogeneousColumnTests, ScalarColumnTests, InterfaceTests | ||
from .base import HeterogeneousColumnTests, InterfaceTests, ScalarColumnTests | ||
|
||
|
||
def create_temp_db(df, name, index=False): | ||
|
@@ -303,3 +313,99 @@ def test_dataset_iloc_ellipsis_list_cols(self): | |
|
||
def test_dataset_boolean_index(self): | ||
raise SkipTest("Not supported") | ||
|
||
def pandas_data(df: pd.DataFrame, *args, **kwargs): | ||
return ibis.pandas.connect({"df": df}) | ||
|
||
def ibis_duckdb_data(df: pd.DataFrame, *args, **kwargs): | ||
tmpdir = kwargs["tmpdir"] | ||
filename = str(Path(tmpdir)/"db.db") | ||
duckdb_con = duckdb.connect(filename) | ||
duckdb_con.execute("CREATE TABLE df AS SELECT * FROM df") | ||
|
||
return ibis.duckdb.connect(filename) | ||
|
||
def ibis_sqlite_data(df: pd.DataFrame, *args, **kwargs): | ||
return create_temp_db(df, "df") | ||
|
||
class IbisMemConnection(param.Parameterized): | ||
def __init__(self, df): | ||
super().__init__() | ||
self._table = ibis.memtable(df) | ||
|
||
def table(self, df): | ||
return self._table | ||
|
||
def ibis_mem_table(df: pd.DataFrame, *args, **kwargs): | ||
return IbisMemConnection(df=df) | ||
|
||
@pytest.fixture | ||
def reference_df(): | ||
return pd.DataFrame( | ||
{ | ||
"actual": [100, 150, 125, 140, 145, 135, 123], | ||
"forecast": [90, 160, 125, 150, 141, 141, 120], | ||
"numerical": [1.1, 1.9, 3.2, 3.8, 4.3, 5.0, 5.5], | ||
"date": pd.date_range("2022-01-03", "2022-01-09"), | ||
"string": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], | ||
}, | ||
) | ||
|
||
@pytest.fixture(params=[pandas_data, ibis_duckdb_data, ibis_sqlite_data, ibis_mem_table]) | ||
def connection(request, reference_df, tmpdir): | ||
return request.param(reference_df, tmpdir=tmpdir) | ||
|
||
@pytest.fixture | ||
def data(connection): | ||
return connection.table("df") | ||
|
||
@pytest.fixture | ||
def dataset(data): | ||
return Dataset(data, kdims=["numerical", "date", "string"], vdims=["actual", "forecast"]) | ||
|
||
def test_get_backend(data): | ||
assert IbisInterface._get_backend(data) | ||
|
||
def test_index_ibis_table(data): | ||
table = IbisInterface._index_ibis_table(data) | ||
table.execute() | ||
|
||
@pytest.mark.parametrize(["dimension", "expected"], [ | ||
("date", (np.datetime64('2022-01-03'), np.datetime64('2022-01-09'))), | ||
("string", ('Mon', 'Sun')), | ||
("numerical",(np.float64(1.1), np.float64(5.5))), | ||
]) | ||
def test_range(dimension, expected, dataset): | ||
assert IbisInterface.range(dataset, dimension) == expected | ||
|
||
@pytest.mark.parametrize(["dimension", "expected"], [ | ||
("date", np.datetime64), | ||
("string", np.object_), | ||
("numerical", np.float64), | ||
]) | ||
def test_dimension_type(dimension, expected, dataset): | ||
assert IbisInterface.dimension_type(dataset, dimension) is expected | ||
|
||
def test_histogram(data): | ||
expr = data[data.actual.notnull()].actual | ||
bins = [90.0, 113.33333333333333, 136.66666666666666, 160.0] | ||
result = IbisInterface.histogram(expr, bins, density=False) | ||
np.testing.assert_array_equal(result[0], np.array([1, 3, 3])) | ||
np.testing.assert_array_equal(result[1], np.array(bins)) | ||
|
||
@pytest.mark.parametrize(["kdims", "vdims", "xaxis_type", "yaxis_type"], [ | ||
("date", "actual", bokeh_axes.DatetimeAxis, bokeh_axes.LinearAxis), | ||
("string", "actual", bokeh_axes.CategoricalAxis, bokeh_axes.LinearAxis), | ||
("numerical", "actual", bokeh_axes.LinearAxis, bokeh_axes.LinearAxis), | ||
("numerical", "date", bokeh_axes.LinearAxis, bokeh_axes.DatetimeAxis), | ||
("numerical", "string", bokeh_axes.LinearAxis, bokeh_axes.CategoricalAxis), | ||
]) | ||
def test_bokeh_axis(data, kdims, vdims, xaxis_type, yaxis_type): | ||
"""Test to make sure the right axis can be identified for the bokeh backend""" | ||
plot_ibis = Curve(data, kdims=kdims, vdims=vdims) | ||
# When | ||
plot_bokeh = render(plot_ibis, "bokeh") | ||
xaxis, yaxis = plot_bokeh.axis | ||
# Then | ||
assert isinstance(xaxis, xaxis_type) | ||
assert isinstance(yaxis, yaxis_type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this one for now. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation seems off.