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

fix bug : open csv file use delimiter other than comma。 #2362

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
6 changes: 4 additions & 2 deletions packages/vaex-core/vaex/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _get_kwargs(obj):
@vaex.dataset.register
class DatasetCsvLazy(DatasetFile):
snake_name = "arrow-csv-lazy"
def __init__(self, path, chunk_size=10*MB, newline_readahead=1*MB, row_count=None, schema=None, read_options=None, parse_options=None, convert_options=None, schema_infer_fraction=0.001, fs=None, fs_options={}):
def __init__(self, path, chunk_size=10*MB, newline_readahead=1*MB, row_count=None, schema=None, read_options=None, parse_options=None, convert_options=None, schema_infer_fraction=0.001, fs=None, fs_options={}, sep=None):
super().__init__(path, fs=fs, fs_options=fs_options)
try:
codec = pa.Codec.detect(self.path)
Expand All @@ -147,6 +147,8 @@ def __init__(self, path, chunk_size=10*MB, newline_readahead=1*MB, row_count=Non
self.chunk_size = parse_bytes(chunk_size)
self.newline_readahead = parse_bytes(newline_readahead)

if sep is not None:
parse_options = _copy_or_create(pyarrow.csv.ParseOptions, parse_options, delimiter=sep)

self.read_options = read_options
self.parse_options = parse_options
Expand Down Expand Up @@ -212,7 +214,7 @@ def _read_table(self, data, first, columns : List[str] = None):
schema = pa.schema([(name, self._schema[name]) for name in columns])
convert_options = _copy_or_create(pyarrow.csv.ConvertOptions, self.convert_options, column_types=schema, include_columns=columns)
try:
table = pyarrow.csv.read_csv(file_like, read_options=read_options, convert_options=convert_options)
table = pyarrow.csv.read_csv(file_like, read_options=read_options, parse_options=self.parse_options, convert_options=convert_options)
except pa.ArrowInvalid as e:
import tempfile
f = tempfile.NamedTemporaryFile(mode="wb", suffix=".csv")
Expand Down