Skip to content

Commit

Permalink
Splitted io test into each format (#2727)
Browse files Browse the repository at this point in the history
  • Loading branch information
illumination-k committed Feb 22, 2022
1 parent 44796e3 commit cb3cf56
Show file tree
Hide file tree
Showing 17 changed files with 922 additions and 687 deletions.
2 changes: 1 addition & 1 deletion py-polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl PyDataFrame {
row_oriented: bool,
json_lines: bool,
) -> PyResult<()> {
let file = get_file_like(py_f, false)?;
let file = get_file_like(py_f, true)?;

let r = match (pretty, row_oriented, json_lines) {
(_, true, true) => panic!("{}", "only one of {row_oriented, json_lines} should be set"),
Expand Down
12 changes: 12 additions & 0 deletions py-polars/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import polars as pl

IO_TEST_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "io"))

EXAMPLES_DIR = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
Expand Down Expand Up @@ -31,6 +33,16 @@
)


@pytest.fixture
def io_test_dir() -> str:
return IO_TEST_DIR


@pytest.fixture
def examples_dir() -> str:
return EXAMPLES_DIR


@pytest.fixture
def foods_csv() -> str:
return FOODS_CSV
Expand Down
5 changes: 5 additions & 0 deletions py-polars/tests/io/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.parquet
*.csv
*.avro
*.ipc
*.json
38 changes: 38 additions & 0 deletions py-polars/tests/io/test_avro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# flake8: noqa: W191,E101
import os
from typing import List

import pytest

import polars as pl
from polars import io


@pytest.fixture
def example_df() -> pl.DataFrame:
return pl.DataFrame({"i64": [1, 2], "f64": [0.1, 0.2], "utf8": ["a", "b"]})


@pytest.fixture
def compressions() -> List[str]:
return ["uncompressed", "snappy", "deflate"]


def test_from_to_buffer(example_df: pl.DataFrame, compressions: List[str]) -> None:
for compression in compressions:
buf = io.BytesIO()
example_df.to_avro(buf, compression=compression) # type: ignore
buf.seek(0)
read_df = pl.read_avro(buf)
assert example_df.frame_equal(read_df)


def test_from_to_file(
io_test_dir: str, example_df: pl.DataFrame, compressions: List[str]
) -> None:
f = os.path.join(io_test_dir, "small.avro")

for compression in compressions:
example_df.to_avro(f, compression=compression) # type: ignore
df_read = pl.read_avro(str(f))
assert example_df.frame_equal(df_read)

0 comments on commit cb3cf56

Please sign in to comment.