@@ -236,23 +236,18 @@ def init_ndarray(values, index, columns, dtype: Optional[DtypeObj], copy: bool):
236
236
# on the entire block; this is to convert if we have datetimelike's
237
237
# embedded in an object type
238
238
if dtype is None and is_object_dtype (values .dtype ):
239
-
240
239
if values .ndim == 2 and values .shape [0 ] != 1 :
241
- # transpose and separate blocks
242
-
243
- dvals_list = [maybe_infer_to_datetimelike (row ) for row in values ]
244
- for n in range (len (dvals_list )):
245
- if isinstance (dvals_list [n ], np .ndarray ):
246
- dvals_list [n ] = dvals_list [n ].reshape (1 , - 1 )
247
-
248
- from pandas .core .internals .blocks import make_block
249
-
250
- # TODO: What about re-joining object columns?
251
- block_values = [
252
- make_block (dvals_list [n ], placement = [n ], ndim = 2 )
253
- for n in range (len (dvals_list ))
254
- ]
255
-
240
+ maybe_datetime = [maybe_infer_to_datetimelike (instance ) for instance in values ]
241
+ # don't convert (and copy) the objects if no type inference occurs
242
+ if any (
243
+ not is_dtype_equal (instance .dtype , values .dtype )
244
+ for instance in maybe_datetime
245
+ ):
246
+ return create_block_manager_from_arrays (
247
+ maybe_datetime , columns , [columns , index ]
248
+ )
249
+ else :
250
+ block_values = [values ]
256
251
else :
257
252
datelike_vals = maybe_infer_to_datetimelike (values )
258
253
block_values = [datelike_vals ]
0 commit comments