forked from AmpX-AI/fsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for PdReader kwargs (AmpX-AI#8)
Co-authored-by: vojta tuma <vtuma@amp.energy>
- Loading branch information
Showing
2 changed files
with
68 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pandas as pd | ||
import pytest | ||
from pandas.testing import assert_frame_equal | ||
|
||
from fsql.api import read_partitioned_table | ||
from fsql.deser import InputFormat, PandasReader | ||
from fsql.query import Q_TRUE | ||
|
||
df1 = pd.DataFrame(data={"c1": [0, 1], "c2": ["hello", "world"]}) | ||
|
||
|
||
def test_input_format_override(tmp_path): | ||
"""Test that explicitly setting format overrides suffix.""" | ||
|
||
case1_path = tmp_path / "table1" | ||
case1_path.mkdir(parents=True) | ||
df1.to_csv(case1_path / "f1.json", index=False) # confuse the default by bad suffix | ||
|
||
with pytest.raises(ValueError, match="Expected object or value"): | ||
# this test condition is quite brittle! A better match would be desired | ||
failure_result = read_partitioned_table(f"file://{case1_path}/", Q_TRUE) | ||
|
||
reader = PandasReader(input_format=InputFormat.CSV) | ||
succ_result = read_partitioned_table(f"file://{case1_path}/", Q_TRUE, data_reader=reader) | ||
assert_frame_equal(df1, succ_result) | ||
|
||
|
||
def test_parquet_kwargs(tmp_path): | ||
"""Test that a kwarg (`columns`) gets passed through and obeyed.""" | ||
|
||
case1_path = tmp_path / "table1" | ||
case1_path.mkdir(parents=True) | ||
df1.to_parquet(case1_path / "f1.parquet", index=False) | ||
|
||
reader = PandasReader(columns=["c2"]) | ||
result = read_partitioned_table(f"file://{case1_path}/", Q_TRUE, data_reader=reader) | ||
assert_frame_equal(df1[["c2"]], result) |