Skip to content

Commit 5ed5908

Browse files
Add to_ibis() method to DataFrame and Series
This commit adds a `to_ibis()` method to both `DataFrame` and `Series` classes. This method allows users to access the underlying Ibis expression (`_data`) for more advanced operations or interoperability with Ibis directly. Tests were added in `tests/test_to_ibis.py` to verify the functionality.
1 parent 3a94b94 commit 5ed5908

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

leanframe/core/frame.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ def to_pandas(self) -> pd.DataFrame:
9191
types_mapper=lambda type_: pd.ArrowDtype(type_)
9292
)
9393

94+
def to_ibis(self) -> ibis_types.Table:
95+
"""Return the underlying Ibis expression."""
96+
return self._data
97+
9498

9599
"""
96100
Dynamic Nested Data Handler for leanframe

leanframe/core/series.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ def to_pandas(self) -> pd.Series:
234234
types_mapper=lambda type_: pd.ArrowDtype(type_)
235235
)
236236

237+
def to_ibis(self) -> ibis_types.Column:
238+
"""Return the underlying Ibis expression."""
239+
return self._data
240+
237241
def to_numpy(self) -> np.ndarray:
238242
"""Return a numpy representation of the Series."""
239243
return self.values

tests/test_to_ibis.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
import pytest
3+
import pandas as pd
4+
import leanframe as lf
5+
import ibis
6+
import ibis.expr.types as ibis_types
7+
from leanframe.core.frame import DataFrame
8+
from leanframe.core.series import Series
9+
10+
def test_dataframe_to_ibis():
11+
# Setup
12+
con = ibis.sqlite.connect()
13+
t = con.create_table('test_df_ibis', schema=ibis.schema({'a': 'int64', 'b': 'string'}))
14+
df = DataFrame(t)
15+
16+
# Execute
17+
expr = df.to_ibis()
18+
19+
# Assert
20+
assert isinstance(expr, ibis_types.Table)
21+
assert expr.equals(t)
22+
23+
def test_series_to_ibis():
24+
# Setup
25+
con = ibis.sqlite.connect()
26+
t = con.create_table('test_series_ibis', schema=ibis.schema({'a': 'int64'}))
27+
s = Series(t['a'])
28+
29+
# Execute
30+
expr = s.to_ibis()
31+
32+
# Assert
33+
assert isinstance(expr, ibis_types.Column)
34+
assert expr.equals(t['a'])

0 commit comments

Comments
 (0)