apache / apache/arrow

[Python] `ArrowInvalid`: CSV conversion error to date32[day]: invalid value '2000-01-01 00:00:00'

Open
#37,180 0 comments 0 reactions 0 assignees View on GitHub
Component: Python Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 13h
Merged PRs (30d)
88

Description

### Describe the bug, including details regarding any error messages, version, and platform.

`pyarrow` has no issue casting timestamps like `'2000-01-01 00:00:00'` to `date32`, but for some reason it doesn't like doing it when reading a CSV. Generally, if types are safe to cast, I'd expect that read_csv can directly convert to the desired type.

```python
from io import BytesIO

import pyarrow as pa
from pyarrow import csv

data = "\n".join(
[
"time,value",
"2000-01-01 00:00:00,-1",
"2000-01-02 00:00:00,-2",
"2000-01-03 00:00:00,-3",
]
)

schema = pa.schema(
{
"time": pa.date32(),
"value": pa.int8(),
}
)

with BytesIO(data.encode("utf8")) as file:
table = csv.read_csv(file)
table = table.cast(schema) # ✔ casting OK

with BytesIO(data.encode("utf8")) as file:
table = csv.read_csv( # ✘ ArrowInvalid
file,
convert_options=csv.ConvertOptions(column_types=schema),
)
```

### Component(s)

Python

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.