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