diff --git a/pandas/_libs/lib.pyx b/pandas/_libs/lib.pyx index 9f2c82d760785..dc8b36a3898b7 100644 --- a/pandas/_libs/lib.pyx +++ b/pandas/_libs/lib.pyx @@ -1986,7 +1986,7 @@ def maybe_convert_numeric(ndarray[object] values, set na_values, Parameters ---------- - values : ndarray + values : ndarray[object] Array of object elements to convert. na_values : set Set of values that should be interpreted as NaN. @@ -2007,7 +2007,8 @@ def maybe_convert_numeric(ndarray[object] values, set na_values, Returns ------- - Array of converted object values to numerical ones. + np.ndarray + Array of converted object values to numerical ones. """ if len(values) == 0: return np.array([], dtype='i8') @@ -2159,7 +2160,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False, Parameters ---------- - values : ndarray + values : ndarray[object] Array of object elements to convert. try_float : bool, default False If an array-like object contains only float or NaN values is @@ -2179,7 +2180,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False, Returns ------- - Array of converted object values to more specific dtypes if applicable. + np.ndarray or ExtensionArray """ cdef: Py_ssize_t i, n @@ -2309,7 +2310,10 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=False, if seen.datetimetz_: if is_datetime_with_singletz_array(objects): from pandas import DatetimeIndex - return DatetimeIndex(objects) + dti = DatetimeIndex(objects) + + # unbox to DatetimeArray + return dti._data seen.object_ = True if not seen.object_: diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 669bfe08d42b0..b80d985f219d5 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -1234,7 +1234,7 @@ def soft_convert_objects( numeric: bool = True, timedelta: bool = True, copy: bool = True, -): +) -> ArrayLike: """ Try to coerce datetime, timedelta, and numeric object-dtype columns to inferred dtype. @@ -1249,7 +1249,7 @@ def soft_convert_objects( Returns ------- - np.ndarray + np.ndarray or ExtensionArray """ validate_bool_kwarg(datetime, "datetime") validate_bool_kwarg(numeric, "numeric") diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index efda1f8038cb7..d12be7f94822c 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -128,7 +128,6 @@ class Block(PandasObject): __slots__ = ["_mgr_locs", "values", "ndim"] is_numeric = False - is_float = False is_bool = False is_object = False is_extension = False @@ -1290,7 +1289,7 @@ def _interpolate( data = self.values if inplace else self.values.copy() # only deal with floats - if not self.is_float: + if self.dtype.kind != "f": if self.dtype.kind not in ["i", "u"]: return [self] data = data.astype(np.float64) @@ -1955,7 +1954,6 @@ def is_bool(self): class FloatBlock(NumericBlock): __slots__ = () - is_float = True def to_native_types( self, na_rep="", float_format=None, decimal=".", quoting=None, **kwargs @@ -2144,7 +2142,6 @@ def to_native_types(self, na_rep="NaT", **kwargs): class DatetimeBlock(DatetimeLikeBlockMixin): __slots__ = () - is_datetime = True fill_value = np.datetime64("NaT", "ns") _dtype = fill_value.dtype _holder = DatetimeArray diff --git a/pandas/tests/reshape/concat/test_concat.py b/pandas/tests/reshape/concat/test_concat.py index 8f18f87f2decc..a125f85efc8d3 100644 --- a/pandas/tests/reshape/concat/test_concat.py +++ b/pandas/tests/reshape/concat/test_concat.py @@ -39,7 +39,7 @@ def test_concat_copy(self): result = concat([df, df2, df3], axis=1, copy=False) for b in result._mgr.blocks: - if b.is_float: + if b.dtype.kind == "f": assert b.values.base is df._mgr.blocks[0].values.base elif b.dtype.kind in ["i", "u"]: assert b.values.base is df2._mgr.blocks[0].values.base @@ -50,7 +50,7 @@ def test_concat_copy(self): df4 = DataFrame(np.random.randn(4, 1)) result = concat([df, df2, df3, df4], axis=1, copy=False) for b in result._mgr.blocks: - if b.is_float: + if b.dtype.kind == "f": assert b.values.base is None elif b.dtype.kind in ["i", "u"]: assert b.values.base is df2._mgr.blocks[0].values.base