Skip to content

Commit

Permalink
fix(clickhouse): workaround clickhouse_connect usage of removed APIs …
Browse files Browse the repository at this point in the history
…in pandas 2.1.0
  • Loading branch information
cpcloud committed Aug 30, 2023
1 parent 2672b7e commit 577599a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 6 additions & 1 deletion ibis/backends/clickhouse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,18 @@ def insert(
**kwargs: Any,
):
import pandas as pd
import pyarrow as pa

if not isinstance(obj, pd.DataFrame):
raise com.IbisError(
f"Invalid input type {type(obj)}; only pandas DataFrames are accepted as input"
)

return self.con.insert_df(name, obj, settings=settings, **kwargs)
# TODO(cpcloud): add support for arrow tables
# TODO(cpcloud): insert_df doesn't work with pandas 2.1.0, move back to
# that (maybe?) when `clickhouse_connect` is fixed
t = pa.Table.from_pandas(obj)
return self.con.insert_arrow(name, t, settings=settings, **kwargs)

def raw_sql(
self,
Expand Down
4 changes: 2 additions & 2 deletions ibis/backends/clickhouse/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_insert_with_less_columns(con, temporary_alltypes, df):
records = df.loc[:10, ["string_col"]].copy()
records["date_col"] = None

with pytest.raises(cc.driver.exceptions.ProgrammingError):
with pytest.raises(cc.driver.exceptions.DatabaseError):
con.insert(temporary.op().name, records)


Expand All @@ -149,7 +149,7 @@ def test_insert_with_more_columns(con, temporary_alltypes, df):
records = df[:10].copy()
records["non_existing_column"] = "raise on me"

with pytest.raises(cc.driver.exceptions.ProgrammingError):
with pytest.raises(cc.driver.exceptions.DatabaseError):
con.insert(temporary.op().name, records)


Expand Down
4 changes: 3 additions & 1 deletion ibis/backends/clickhouse/tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,9 @@ def test_asof_join(time_left, time_right):
expected = pd.merge_asof(
time_left.execute(), time_right.execute(), on="time", suffixes=("", "_right")
)
tm.assert_frame_equal(result[expected.columns], expected)
tm.assert_frame_equal(
result[expected.columns].fillna(pd.NA), expected.fillna(pd.NA)
)


def test_count_name(snapshot):
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/clickhouse/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_columns_types_with_additional_argument(con):
]
df = con.sql(f"SELECT {', '.join(sql_types)}").execute()
assert df.fixedstring_col.dtype.name == "object"
assert df.datetime_col.dtype.name == "datetime64[s, UTC]"
assert df.datetime_col.dtype.name in ("datetime64[ns, UTC]", "datetime64[s, UTC]")
assert df.datetime_ns_col.dtype.name == "datetime64[ns, UTC]"


Expand Down

0 comments on commit 577599a

Please sign in to comment.