Skip to content

Commit

Permalink
Make mypy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Sep 7, 2023
1 parent 2b04ae2 commit 6a82d0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
2 changes: 0 additions & 2 deletions py-polars/polars/io/iceberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ def _(a: Call) -> Any:
return IsNull(ref)
elif f == "is_nan":
return IsNaN(ref)
elif f == "scalar":
return AlwaysTrue() if args[0] else AlwaysFalse()

raise ValueError(f"Unknown call: {f}")

Expand Down
30 changes: 13 additions & 17 deletions py-polars/tests/unit/io/test_iceberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@
import contextlib
import os
from pathlib import Path
from typing import TYPE_CHECKING

import pytest

import polars as pl
from polars.io.iceberg import _convert_predicate, _to_ast

if TYPE_CHECKING:
from pyiceberg.expressions import BooleanExpression


@pytest.fixture()
def iceberg_path() -> str:
# Iceberg requires absolute paths, so we'll symlink
# the test table into /tmp/iceberg/t1/
Path("/tmp/iceberg").mkdir(parents=True, exist_ok=True)
current_path = Path.cwd()
print("path:")
print(f"{current_path}/files/iceberg-table")
print("dir:")
print(os.listdir(f"{current_path}/files/iceberg-table"))
current_path = os.path.dirname(__file__)
with contextlib.suppress(FileExistsError):
os.symlink(f"{current_path}/files/iceberg-table", "/tmp/iceberg/t1")
print("linked:")
print(os.listdir("/tmp/iceberg/t1"))

return "file:///tmp/iceberg/t1/metadata/00001-55cdf97b-255c-4983-b9f3-0e468fadfe9e.metadata.json"

Expand All @@ -39,20 +49,6 @@ def test_scan_iceberg_filter_on_column(iceberg_path: str) -> None:
assert len(df.collect()) == 1192


def test_true_expression() -> None:
from pyiceberg.expressions import AlwaysTrue

expr = _to_ast("pa.compute.scalar(True)")
assert _convert_predicate(expr) == AlwaysTrue()


def test_false_expression() -> None:
from pyiceberg.expressions import AlwaysFalse

expr = _to_ast("pa.compute.scalar(False)")
assert _convert_predicate(expr) == AlwaysFalse()


def test_is_null_expression() -> None:
from pyiceberg.expressions import IsNull

Expand Down Expand Up @@ -82,7 +78,7 @@ def test_is_not_nan_expression() -> None:


def test_isin_expression() -> None:
from pyiceberg.expressions import In, literal
from pyiceberg.expressions import In, literal # type: ignore[attr-defined]

expr = _to_ast("(pa.compute.field('location_id')).isin([1,2,3])")
assert _convert_predicate(expr) == In(
Expand All @@ -91,7 +87,7 @@ def test_isin_expression() -> None:


def test_parse_combined_expression() -> None:
from pyiceberg.expressions import (
from pyiceberg.expressions import ( # type: ignore[attr-defined]
And,
EqualTo,
GreaterThan,
Expand Down

0 comments on commit 6a82d0d

Please sign in to comment.