|
76 | 76 | ArrayManager,
|
77 | 77 | SingleArrayManager,
|
78 | 78 | )
|
79 |
| -from pandas.core.internals.blocks import ( |
80 |
| - ensure_block_shape, |
81 |
| - new_block, |
82 |
| -) |
83 | 79 | from pandas.core.internals.managers import (
|
84 | 80 | BlockManager,
|
85 | 81 | SingleBlockManager,
|
| 82 | + create_block_manager_from_array, |
86 | 83 | create_block_manager_from_arrays,
|
87 |
| - create_block_manager_from_blocks, |
88 | 84 | )
|
89 | 85 |
|
90 | 86 | if TYPE_CHECKING:
|
@@ -340,42 +336,29 @@ def ndarray_to_mgr(
|
340 | 336 |
|
341 | 337 | return ArrayManager(arrays, [index, columns], verify_integrity=False)
|
342 | 338 |
|
343 |
| - values = values.T |
| 339 | + array = values.T |
344 | 340 |
|
345 | 341 | # if we don't have a dtype specified, then try to convert objects
|
346 | 342 | # on the entire block; this is to convert if we have datetimelike's
|
347 | 343 | # embedded in an object type
|
348 |
| - if dtype is None and is_object_dtype(values.dtype): |
349 |
| - |
350 |
| - if values.ndim == 2 and values.shape[0] != 1: |
| 344 | + if dtype is None and is_object_dtype(array.dtype): |
| 345 | + if array.ndim == 2 and array.shape[0] != 1: |
351 | 346 | # transpose and separate blocks
|
352 |
| - |
353 |
| - dtlike_vals = [maybe_infer_to_datetimelike(row) for row in values] |
| 347 | + maybe_datetime = [ |
| 348 | + maybe_infer_to_datetimelike(instance) for instance in array |
| 349 | + ] |
354 | 350 | # don't convert (and copy) the objects if no type inference occurs
|
355 | 351 | if any(
|
356 |
| - not is_dtype_equal(instance.dtype, values.dtype) |
357 |
| - for instance in dtlike_vals |
| 352 | + not is_dtype_equal(instance.dtype, array.dtype) |
| 353 | + for instance in maybe_datetime |
358 | 354 | ):
|
359 |
| - dvals_list = [ensure_block_shape(dval, 2) for dval in dtlike_vals] |
360 |
| - block_values = [ |
361 |
| - new_block(dvals_list[n], placement=n, ndim=2) |
362 |
| - for n in range(len(dvals_list)) |
363 |
| - ] |
364 |
| - else: |
365 |
| - nb = new_block(values, placement=slice(len(columns)), ndim=2) |
366 |
| - block_values = [nb] |
| 355 | + return create_block_manager_from_arrays( |
| 356 | + maybe_datetime, columns, [columns, index] |
| 357 | + ) |
367 | 358 | else:
|
368 |
| - datelike_vals = maybe_infer_to_datetimelike(values) |
369 |
| - nb = new_block(datelike_vals, placement=slice(len(columns)), ndim=2) |
370 |
| - block_values = [nb] |
371 |
| - else: |
372 |
| - nb = new_block(values, placement=slice(len(columns)), ndim=2) |
373 |
| - block_values = [nb] |
374 |
| - |
375 |
| - if len(columns) == 0: |
376 |
| - block_values = [] |
| 359 | + array = maybe_infer_to_datetimelike(array) |
377 | 360 |
|
378 |
| - return create_block_manager_from_blocks(block_values, [columns, index]) |
| 361 | + return create_block_manager_from_array(array, [columns, index]) |
379 | 362 |
|
380 | 363 |
|
381 | 364 | def _check_values_indices_shape_match(
|
|
0 commit comments