Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions leanframe/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def to_pandas(self) -> pd.DataFrame:
types_mapper=lambda type_: pd.ArrowDtype(type_)
)

def to_ibis(self) -> ibis_types.Table:
"""Return the underlying Ibis expression."""
return self._data


"""
Dynamic Nested Data Handler for leanframe
Expand Down
4 changes: 4 additions & 0 deletions leanframe/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ def to_pandas(self) -> pd.Series:
types_mapper=lambda type_: pd.ArrowDtype(type_)
)

def to_ibis(self) -> ibis_types.Column:
"""Return the underlying Ibis expression."""
return self._data

def to_numpy(self) -> np.ndarray:
"""Return a numpy representation of the Series."""
return self.values
Expand Down
31 changes: 31 additions & 0 deletions tests/test_to_ibis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

import ibis
import ibis.expr.types as ibis_types
from leanframe.core.frame import DataFrame
from leanframe.core.series import Series

def test_dataframe_to_ibis():
# Setup
con = ibis.sqlite.connect()
t = con.create_table('test_df_ibis', schema=ibis.schema({'a': 'int64', 'b': 'string'}))
df = DataFrame(t)

# Execute
expr = df.to_ibis()

# Assert
assert isinstance(expr, ibis_types.Table)
assert expr.equals(t)

def test_series_to_ibis():
# Setup
con = ibis.sqlite.connect()
t = con.create_table('test_series_ibis', schema=ibis.schema({'a': 'int64'}))
s = Series(t['a'])

# Execute
expr = s.to_ibis()

# Assert
assert isinstance(expr, ibis_types.Column)
assert expr.equals(t['a'])