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

Test the CSV read with column types specified #24398

Merged
merged 7 commits into from
May 7, 2022
Merged
Changes from 2 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
27 changes: 27 additions & 0 deletions python/ray/data/tests/test_dataset_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,33 @@ def test_csv_read_no_header(shutdown_only, tmp_path):
assert df.equals(out_df)


def test_csv_read_with_column_type_specified(shutdown_only, tmp_path):
from pyarrow import csv

file_path = os.path.join(str(tmp_path), "test.csv")
df = pd.DataFrame({"one": [1, 2, 3e+5], "two": ["a", "b", "c"]})
df.to_csv(file_path)

# Incorrect to parse scientific notation in int64 as PyArrow represents
# it as double.
with pytest.raises(pa.lib.ArrowInvalid):
ray.data.read_csv(
file_path,
convert_options=csv.ConvertOptions(
column_types={"one": "int64", "two": "string"}),
)

# Parsing scientific notation in double shoud work.
ds = ray.data.read_csv(
file_path,
convert_options=csv.ConvertOptions(
column_types={"one": "float64", "two": "string"}),
)
expected_df = pd.DataFrame(
{"one": [1.0, 2.0, 3e+5], "two": ["a", "b", "c"]})
assert df.equals(expected_df)
scv119 marked this conversation as resolved.
Show resolved Hide resolved


class NodeLoggerOutputDatasource(Datasource[Union[ArrowRow, int]]):
"""A writable datasource that logs node IDs of write tasks, for testing."""

Expand Down