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

remove upper bound of plugin dependencies for flytekit-polars #2514

Merged
merged 8 commits into from
Aug 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ class PolarsDataFrameRenderer:

def to_html(self, df: pl.DataFrame) -> str:
assert isinstance(df, pl.DataFrame)
describe_df = df.describe()
return pd.DataFrame(describe_df.transpose(), columns=describe_df.columns).to_html(index=False)
return df.describe().to_pandas().to_html(index=False)


class PolarsDataFrameToParquetEncodingHandler(StructuredDatasetEncoder):
Expand Down
2 changes: 1 addition & 1 deletion plugins/flytekit-polars/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

microlib_name = f"flytekitplugins-{PLUGIN_NAME}"

plugin_requires = ["flytekit>=1.3.0b2,<2.0.0", "polars>=0.8.27,<0.17.0", "pandas"]
plugin_requires = ["flytekit>=1.3.0b2,<2.0.0", "polars>=0.8.27", "pandas"]

__version__ = "0.0.0+develop"

Expand Down
16 changes: 10 additions & 6 deletions plugins/flytekit-polars/tests/test_polars_plugin_sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
import polars as pl
from flytekitplugins.polars.sd_transformers import PolarsDataFrameRenderer
from typing_extensions import Annotated
from packaging import version
from polars.testing import assert_frame_equal

from flytekit import kwtypes, task, workflow
from flytekit.types.structured.structured_dataset import PARQUET, StructuredDataset

subset_schema = Annotated[StructuredDataset, kwtypes(col2=str), PARQUET]
full_schema = Annotated[StructuredDataset, PARQUET]

polars_version = pl.__version__


def test_polars_workflow_subset():
@task
Expand Down Expand Up @@ -65,9 +69,9 @@ def wf() -> full_schema:

def test_polars_renderer():
df = pl.DataFrame({"col1": [1, 3, 2], "col2": list("abc")})
assert PolarsDataFrameRenderer().to_html(df) == pd.DataFrame(
df.describe().transpose(), columns=df.describe().columns
).to_html(index=False)
assert PolarsDataFrameRenderer().to_html(df) == df.describe().to_pandas().to_html(
index=False
)


def test_parquet_to_polars():
Expand All @@ -80,7 +84,7 @@ def create_sd() -> StructuredDataset:

sd = create_sd()
polars_df = sd.open(pl.DataFrame).all()
assert pl.DataFrame(data).frame_equal(polars_df)
assert_frame_equal(polars_df, pl.DataFrame(data))

tmp = tempfile.mktemp()
pl.DataFrame(data).write_parquet(tmp)
Expand All @@ -90,11 +94,11 @@ def t1(sd: StructuredDataset) -> pl.DataFrame:
return sd.open(pl.DataFrame).all()

sd = StructuredDataset(uri=tmp)
assert t1(sd=sd).frame_equal(polars_df)
assert_frame_equal(t1(sd=sd), polars_df)

@task
def t2(sd: StructuredDataset) -> StructuredDataset:
return StructuredDataset(dataframe=sd.open(pl.DataFrame).all())

sd = StructuredDataset(uri=tmp)
assert t2(sd=sd).open(pl.DataFrame).all().frame_equal(polars_df)
assert_frame_equal(t2(sd=sd).open(pl.DataFrame).all(), polars_df)
Loading