diff --git a/cpp/src/arrow/compute/kernels/scalar_cast_temporal.cc b/cpp/src/arrow/compute/kernels/scalar_cast_temporal.cc index a5612643913aa..8782173f87969 100644 --- a/cpp/src/arrow/compute/kernels/scalar_cast_temporal.cc +++ b/cpp/src/arrow/compute/kernels/scalar_cast_temporal.cc @@ -510,9 +510,12 @@ void AddCrossUnitCastNoPreallocate(CastFunction* func) { std::shared_ptr GetDate32Cast() { auto func = std::make_shared("cast_date32", Type::DATE32); - auto out_ty = date32(); + const auto& out_ty = date32(); AddCommonCasts(Type::DATE32, out_ty, func.get()); + // date32 -> date32 + AddCrossUnitCast(func.get()); + // int32 -> date32 AddZeroCopyCast(Type::INT32, int32(), date32(), func.get()); @@ -532,9 +535,12 @@ std::shared_ptr GetDate32Cast() { std::shared_ptr GetDate64Cast() { auto func = std::make_shared("cast_date64", Type::DATE64); - auto out_ty = date64(); + const auto out_ty = date64(); AddCommonCasts(Type::DATE64, out_ty, func.get()); + // date64 -> date64 + AddCrossUnitCast(func.get()); + // int64 -> date64 AddZeroCopyCast(Type::INT64, int64(), date64(), func.get()); diff --git a/python/pyarrow/tests/test_ipc.py b/python/pyarrow/tests/test_ipc.py index 1e5242efe40f0..6d4bda72b320c 100644 --- a/python/pyarrow/tests/test_ipc.py +++ b/python/pyarrow/tests/test_ipc.py @@ -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():