apache / apache/arrow

[C++][Python] Compute function to generate date from year / month / day

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

Description

### Describe the enhancement requested

There are currently pyarrow functions converting a `pa.date32()` to its year / month / day. But there isn't a function that does the invert, accepting a year, a month and a day and returning a `pa.date32`.

The current work around involve either using python `datetime.date` (but it is slow and the range is limited). Alternatively one can build a date string from the component and parse it. But it's far from ideal

```
import pyarrow as pa
import pyarrow.compute as pc

table = pa.table({"year": [2024, 2025], "month": [3, 7], "day": [10, 4]})

date_str = pc.binary_join_element_wise(
pc.cast(table["year"], pa.string()),
pc.utf8_lpad(pc.cast(table["month"], pa.string()), 2, "0"),
pc.utf8_lpad(pc.cast(table["day"], pa.string()), 2, "0"),
"-"
)

dates = pc.cast(date_str, pa.date32())
```

### 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.