|
85 | 85 |
|
86 | 86 | from pandas.core.dtypes.cast import (
|
87 | 87 | construct_1d_arraylike_from_scalar,
|
| 88 | + construct_2d_arraylike_from_scalar, |
88 | 89 | find_common_type,
|
89 | 90 | infer_dtype_from_scalar,
|
90 | 91 | invalidate_string_dtypes,
|
91 | 92 | maybe_box_datetimelike,
|
92 | 93 | maybe_convert_platform,
|
93 | 94 | maybe_downcast_to_dtype,
|
94 | 95 | maybe_infer_to_datetimelike,
|
95 |
| - maybe_unbox_datetimelike, |
96 | 96 | validate_numeric_casting,
|
97 | 97 | )
|
98 | 98 | from pandas.core.dtypes.common import (
|
@@ -595,31 +595,17 @@ def __init__(
|
595 | 595 |
|
596 | 596 | # For data is a scalar extension dtype
|
597 | 597 | if is_extension_array_dtype(dtype):
|
| 598 | + # TODO(EA2D): special case not needed with 2D EAs |
598 | 599 |
|
599 | 600 | values = [
|
600 | 601 | construct_1d_arraylike_from_scalar(data, len(index), dtype)
|
601 | 602 | for _ in range(len(columns))
|
602 | 603 | ]
|
603 | 604 | mgr = arrays_to_mgr(values, columns, index, columns, dtype=None)
|
604 | 605 | else:
|
605 |
| - if dtype.kind in ["m", "M"]: |
606 |
| - data = maybe_unbox_datetimelike(data, dtype) |
607 |
| - |
608 |
| - # Attempt to coerce to a numpy array |
609 |
| - try: |
610 |
| - arr = np.array(data, dtype=dtype, copy=copy) |
611 |
| - except (ValueError, TypeError) as err: |
612 |
| - exc = TypeError( |
613 |
| - "DataFrame constructor called with " |
614 |
| - f"incompatible data and dtype: {err}" |
615 |
| - ) |
616 |
| - raise exc from err |
617 |
| - |
618 |
| - if arr.ndim != 0: |
619 |
| - raise ValueError("DataFrame constructor not properly called!") |
620 |
| - |
621 |
| - shape = (len(index), len(columns)) |
622 |
| - values = np.full(shape, arr) |
| 606 | + values = construct_2d_arraylike_from_scalar( |
| 607 | + data, len(index), len(columns), dtype, copy |
| 608 | + ) |
623 | 609 |
|
624 | 610 | mgr = init_ndarray(
|
625 | 611 | values, index, columns, dtype=values.dtype, copy=False
|
|
0 commit comments