Skip to content

Commit

Permalink
GH-43183: [C++] Add date{32,64} to date{32,64} cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Jul 8, 2024
1 parent e8a795b commit ce5bd92
Show file tree
Hide file tree
Showing 2 changed files with 27 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
19 changes: 19 additions & 0 deletions python/pyarrow/tests/test_ipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,25 @@ def make_batches():
reader = pa.RecordBatchReader.from_batches(None, batches)
pass

# https://github.com/apache/arrow/issues/43183
dt = datetime.date(1990, 3, 1)
data = [[dt], [dt]]

schema = pa.schema([
('date32', pa.date32()),
('date64', pa.date64()),
])

batch = pa.RecordBatch.from_arrays(data, schema=schema)

table = pa.RecordBatchReader.from_batches(
schema,
[batch]
).read_all()

assert table['date32'][0].as_py() == dt
assert table['date64'][0].as_py() == dt


def test_record_batch_reader_from_arrow_stream():

Expand Down

0 comments on commit ce5bd92

Please sign in to comment.