Skip to content

Commit

Permalink
GH-43183: [C++] Add date to date cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Jul 8, 2024
1 parent e8a795b commit 9c8a433
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cpp/src/arrow/compute/kernels/scalar_cast_temporal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,12 @@ void AddCrossUnitCastNoPreallocate(CastFunction* func) {

std::shared_ptr<CastFunction> GetDate32Cast() {
auto func = std::make_shared<CastFunction>("cast_date32", Type::DATE32);
auto out_ty = date32();
const auto& out_ty = date32();
AddCommonCasts(Type::DATE32, out_ty, func.get());

// date32 -> date32
AddCrossUnitCast<Date32Type>(func.get());

// int32 -> date32
AddZeroCopyCast(Type::INT32, int32(), date32(), func.get());

Expand All @@ -532,9 +535,12 @@ std::shared_ptr<CastFunction> GetDate32Cast() {

std::shared_ptr<CastFunction> GetDate64Cast() {
auto func = std::make_shared<CastFunction>("cast_date64", Type::DATE64);
auto out_ty = date64();
const auto out_ty = date64();
AddCommonCasts(Type::DATE64, out_ty, func.get());

// date64 -> date64
AddCrossUnitCast<Date64Type>(func.get());

// int64 -> date64
AddZeroCopyCast(Type::INT64, int64(), date64(), func.get());

Expand Down
12 changes: 12 additions & 0 deletions python/pyarrow/tests/test_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,18 @@ def make_batches():
reader = pa.RecordBatchReader.from_batches(None, batches)
pass

# https://github.com/apache/arrow/issues/43183
data = [[datetime.date(1990, 3, 1)]]
batch = pa.RecordBatch.from_arrays(data, names=['dates'])
schema = pa.schema([
('dates', pa.date32()),
])

assert pa.RecordBatchReader.from_batches(
schema,
[batch]
).cast(schema).read_all() == [[data]]


def test_record_batch_reader_from_arrow_stream():

Expand Down

0 comments on commit 9c8a433

Please sign in to comment.