@@ -461,27 +461,23 @@ def maybe_cast_pointwise_result(
461
461
"""
462
462
463
463
if isinstance (dtype , ExtensionDtype ):
464
- if not isinstance (dtype , (CategoricalDtype , DatetimeTZDtype , ArrowDtype )):
464
+ if not isinstance (dtype , (CategoricalDtype , DatetimeTZDtype )):
465
465
# TODO: avoid this special-casing
466
466
# We have to special case categorical so as not to upcast
467
467
# things like counts back to categorical
468
-
469
- cls = dtype .construct_array_type ()
470
- if same_dtype :
471
- result = _maybe_cast_to_extension_array (cls , result , dtype = dtype )
472
- else :
473
- result = _maybe_cast_to_extension_array (cls , result )
474
- elif isinstance (dtype , ArrowDtype ):
475
- pyarrow_type = convert_dtypes (result , dtype_backend = "pyarrow" )
476
- if isinstance (pyarrow_type , ExtensionDtype ):
477
- cls = pyarrow_type .construct_array_type ()
478
- result = _maybe_cast_to_extension_array (cls , result )
468
+ if isinstance (dtype , ArrowDtype ):
469
+ pyarrow_type = convert_dtypes (result , dtype_backend = "pyarrow" )
479
470
else :
471
+ pyarrow_type = np .dtype ("object" )
472
+ if not isinstance (pyarrow_type , ExtensionDtype ):
480
473
cls = dtype .construct_array_type ()
481
474
if same_dtype :
482
475
result = _maybe_cast_to_extension_array (cls , result , dtype = dtype )
483
476
else :
484
477
result = _maybe_cast_to_extension_array (cls , result )
478
+ else :
479
+ cls = pyarrow_type .construct_array_type ()
480
+ result = _maybe_cast_to_extension_array (cls , result )
485
481
elif (numeric_only and dtype .kind in "iufcb" ) or not numeric_only :
486
482
result = maybe_downcast_to_dtype (result , dtype )
487
483
0 commit comments