Skip to content
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

Add read API to convert result to Polars #30

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions dev/dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ pytz>=2018.3
pytest~=7.0
duckdb>=0.5.0,<2.0.0
ray~=2.10.0
polars~=1.15.0
5 changes: 5 additions & 0 deletions paimon_python_api/table_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#################################################################################

import pandas as pd
import polars as pl
import pyarrow as pa
import ray

Expand All @@ -41,6 +42,10 @@ def to_arrow_batch_reader(self, splits: List[Split]) -> pa.RecordBatchReader:
def to_pandas(self, splits: List[Split]) -> pd.DataFrame:
"""Read data from splits and converted to pandas.DataFrame format."""

@abstractmethod
def to_polars(self, splits: List[Split]) -> pl.DataFrame:
"""Read data from splits and converted to polars.DataFrame format."""

@abstractmethod
def to_duckdb(
self,
Expand Down
4 changes: 4 additions & 0 deletions paimon_python_java/pypaimon.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import duckdb
import pandas as pd
import polars as pl
import pyarrow as pa
import ray

Expand Down Expand Up @@ -164,6 +165,9 @@ def to_arrow_batch_reader(self, splits):
def to_pandas(self, splits: List[Split]) -> pd.DataFrame:
return self.to_arrow(splits).to_pandas()

def to_polars(self, splits: List[Split]) -> pl.DataFrame:
return pl.from_arrow(self.to_arrow(splits))

def to_duckdb(
self,
splits: List[Split],
Expand Down
6 changes: 6 additions & 0 deletions paimon_python_java/tests/test_write_and_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import unittest
import pandas as pd
import pyarrow as pa
import polars as pl
from py4j.protocol import Py4JJavaError

from polars import testing as pl_testing
from paimon_python_api import Schema
from paimon_python_java import Catalog
from paimon_python_java.java_gateway import get_gateway
Expand Down Expand Up @@ -297,6 +299,10 @@ def testAllWriteAndReadApi(self):
pd.testing.assert_frame_equal(
actual.reset_index(drop=True), all_data.reset_index(drop=True))

# to_polars
pl_df = table_read.to_polars(splits)
pl_testing.assert_frame_equal(pl_df, pl.from_pandas(all_data))

# to_duckdb
duckdb_con = table_read.to_duckdb(splits, 'duckdb_table')
# select *
Expand Down
Loading