diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 0ad652bd5aa64..792fa4fdc24a5 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -361,15 +361,11 @@ def trans(x): # if we don't have any elements, just astype it return trans(result).astype(dtype) - # do a test on the first element, if it fails then we are done - r = result.ravel() - arr = np.array([r[0]]) - - if isna(arr).any(): - # if we have any nulls, then we are done - return result - - elif not isinstance(r[0], (np.integer, np.floating, int, float, bool)): + if isinstance(result, np.ndarray): + element = result.item(0) + else: + element = result.iloc[0] + if not isinstance(element, (np.integer, np.floating, int, float, bool)): # a comparable, e.g. a Decimal may slip in here return result