felipecrv commented on code in PR #42098:
URL: https://github.com/apache/arrow/pull/42098#discussion_r1636858505


##########
python/pyarrow/tests/test_ipc.py:
##########
@@ -1272,6 +1273,15 @@ def test_record_batch_reader_cast():
     with pytest.raises(pa.lib.ArrowTypeError, match='Field 0 cannot be cast'):
         reader.cast(pa.schema([pa.field('a', pa.list_(pa.int32()))]))
 
+    # Cast to same type should always work also for date32
+    # (https://github.com/apache/arrow/issues/41884)

Review Comment:
   The "...also for date32" is misleading here, right? Since casts are broken 
for all pairs of equal types.



##########
python/pyarrow/src/arrow/python/ipc.cc:
##########
@@ -79,7 +79,8 @@ Status 
CastingRecordBatchReader::Init(std::shared_ptr<RecordBatchReader> parent,
 
   // Ensure all columns can be cast before succeeding
   for (int i = 0; i < num_fields; i++) {
-    if (!compute::CanCast(*src->field(i)->type(), *schema->field(i)->type())) {
+    if ((!((src->field(i)->type()->Equals(schema->field(i)->type())))) &&
+        (!compute::CanCast(*src->field(i)->type(), 
*schema->field(i)->type()))) {

Review Comment:
   I checked the `CanCast` calls and most of them check equality first [1], so 
this is indeed the right and proper fix.
   
   [1] because `CanCast` is based on the existence of a cast function that 
actually changes types and not the identity function (very error-prone, but it 
is what it is).



##########
python/pyarrow/src/arrow/python/ipc.cc:
##########
@@ -79,7 +79,8 @@ Status 
CastingRecordBatchReader::Init(std::shared_ptr<RecordBatchReader> parent,
 
   // Ensure all columns can be cast before succeeding
   for (int i = 0; i < num_fields; i++) {
-    if (!compute::CanCast(*src->field(i)->type(), *schema->field(i)->type())) {
+    if ((!((src->field(i)->type()->Equals(schema->field(i)->type())))) &&
+        (!compute::CanCast(*src->field(i)->type(), 
*schema->field(i)->type()))) {

Review Comment:
   ```suggestion
       auto& src_type = src->field(i)->type();
       auto& schema_type = schema->field(i)->type();
       if (!src_type->Equals(schema_type) && !compute::CanCast(*src_type, 
*schema_type)) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to