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