Skip to content

Commit

Permalink
test(python): Parametrize test_parquet_datetime (#5696)
Browse files Browse the repository at this point in the history
Co-authored-by: Ritchie Vink <ritchie46@gmail.com>
  • Loading branch information
jjerphan and ritchie46 committed Dec 2, 2022
1 parent f40ab04 commit 51c5562
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions py-polars/tests/unit/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@
if TYPE_CHECKING:
from polars.internals.type_aliases import ParquetCompression

COMPRESSIONS: list[ParquetCompression] = [
"lz4",
"uncompressed",
"snappy",
"gzip",
"lzo",
"brotli",
"zstd",
]


@pytest.fixture
def compressions() -> list[ParquetCompression]:
return ["lz4", "uncompressed", "snappy", "gzip", "lzo", "brotli", "zstd"]
return COMPRESSIONS


def test_to_from_buffer(
Expand Down Expand Up @@ -119,7 +129,16 @@ def test_parquet_chunks() -> None:
assert pl.DataFrame(df).frame_equal(polars_df)


def test_parquet_datetime() -> None:
@pytest.mark.parametrize("use_pyarrow", [True, False])
@pytest.mark.parametrize("compression", COMPRESSIONS)
def test_parquet_datetime(use_pyarrow: bool, compression: ParquetCompression) -> None:
if compression == "lzo":
back_end = "C++" if use_pyarrow else "Rust"
pytest.skip(
f"LZO compression is not currently not supported by the {back_end}"
f"implementation of Arrow."
)

# This failed because parquet writers cast datetime to Date
f = io.BytesIO()
data = {
Expand All @@ -136,8 +155,7 @@ def test_parquet_datetime() -> None:
df = pl.DataFrame(data)
df = df.with_column(df["datetime"].cast(pl.Datetime))

# todo! test all compressions here
df.write_parquet(f, use_pyarrow=True, compression="snappy")
df.write_parquet(f, use_pyarrow=use_pyarrow, compression=compression)
f.seek(0)
read = pl.read_parquet(f)
assert read.frame_equal(df)
Expand Down

0 comments on commit 51c5562

Please sign in to comment.