duckdb icon indicating copy to clipboard operation
duckdb copied to clipboard

read_csv_auto() ignore_errors stopped working in v0.9

Open hd-code opened this issue 3 years ago • 2 comments

What happens?

Ever since updating to v0.9.2 the ignore_errors parameter for read_csv_auto seems not to be working anymore.

Running the code below with v0.8.1 works seamlessly. For v0.9.0, v0.9.1 and v0.9.2 I get the following error:

duckdb.duckdb.InvalidInputException: Invalid Input Error: Error in file "data.csv": CSV options could not be auto-detected. Consider setting parser options manually.

To Reproduce

I isolated the behavior, so only the following packages have to be installed:
pip install duckdb numpy pandas

The following script creates a csv file with random numbers. It also appends a text line to the file (so an error). Then I try to read the file back with duckdb.

import duckdb
import numpy as np
import pandas as pd


def _make_csv(filename: str):
    cols = list("abcdefghij")
    n_cols = len(cols)
    n_rows = 10000

    np.random.seed(0)
    data = np.random.normal(10, 5, size=(n_rows, n_cols))
    df = pd.DataFrame(data, columns=cols)

    df.to_csv(filename, header=True, index=False, sep="\t")


def _append_error_line(filename: str):
    with open(filename, "a") as file:
        text = """some error line"""
        file.write(text)


def _parse_csv(filename: str):
    query = """
        SELECT *
        FROM read_csv_auto('%s', ignore_errors=True)
    """ % filename
    result = duckdb.sql(query)
    result.show()


if __name__ == "__main__":
    filename = "data.csv"
    _make_csv(filename)
    _append_error_line(filename)
    _parse_csv(filename)

OS:

Ubuntu 22.04.3 LTS x64

DuckDB Version:

0.9.2

DuckDB Client:

Python

Full Name:

Hannes Dröse

Affiliation:

German Aerospace Center (DLR)

Have you tried this on the latest main branch?

I have tested with a release build (and could not test with a main build)

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • [X] Yes, I have

hd-code avatar Nov 20 '23 15:11 hd-code

It seems to work fine on the main branch already, could you give it a go with it and confirm that the issue is resolved? You can build the python client with

BUILD_PYTHON=1 make

pdet avatar Nov 27 '23 13:11 pdet

I tested it with main and it works fine. So, it seems to be resolved. Thank you

hd-code avatar Nov 27 '23 21:11 hd-code