|
34 | 34 | from pandas.core.dtypes.common import (
|
35 | 35 | is_1d_only_ea_dtype,
|
36 | 36 | is_datetime64tz_dtype,
|
| 37 | + is_datetime_or_timedelta_dtype, |
37 | 38 | is_dtype_equal,
|
38 | 39 | is_extension_array_dtype,
|
39 | 40 | is_integer_dtype,
|
|
60 | 61 | TimedeltaArray,
|
61 | 62 | )
|
62 | 63 | from pandas.core.construction import (
|
| 64 | + ensure_wrapped_if_datetimelike, |
63 | 65 | extract_array,
|
64 | 66 | sanitize_array,
|
65 | 67 | )
|
@@ -316,10 +318,30 @@ def ndarray_to_mgr(
|
316 | 318 | index, columns = _get_axes(
|
317 | 319 | values.shape[0], values.shape[1], index=index, columns=columns
|
318 | 320 | )
|
319 |
| - values = values.T |
320 | 321 |
|
321 | 322 | _check_values_indices_shape_match(values, index, columns)
|
322 | 323 |
|
| 324 | + if typ == "array": |
| 325 | + |
| 326 | + if issubclass(values.dtype.type, str): |
| 327 | + values = np.array(values, dtype=object) |
| 328 | + |
| 329 | + if dtype is None and is_object_dtype(values.dtype): |
| 330 | + arrays = [ |
| 331 | + ensure_wrapped_if_datetimelike( |
| 332 | + maybe_infer_to_datetimelike(values[:, i].copy()) |
| 333 | + ) |
| 334 | + for i in range(values.shape[1]) |
| 335 | + ] |
| 336 | + else: |
| 337 | + if is_datetime_or_timedelta_dtype(values.dtype): |
| 338 | + values = ensure_wrapped_if_datetimelike(values) |
| 339 | + arrays = [values[:, i].copy() for i in range(values.shape[1])] |
| 340 | + |
| 341 | + return ArrayManager(arrays, [index, columns], verify_integrity=False) |
| 342 | + |
| 343 | + values = values.T |
| 344 | + |
323 | 345 | # if we don't have a dtype specified, then try to convert objects
|
324 | 346 | # on the entire block; this is to convert if we have datetimelike's
|
325 | 347 | # embedded in an object type
|
@@ -358,13 +380,13 @@ def _check_values_indices_shape_match(
|
358 | 380 | Check that the shape implied by our axes matches the actual shape of the
|
359 | 381 | data.
|
360 | 382 | """
|
361 |
| - if values.shape[0] != len(columns): |
| 383 | + if values.shape[1] != len(columns) or values.shape[0] != len(index): |
362 | 384 | # Could let this raise in Block constructor, but we get a more
|
363 | 385 | # helpful exception message this way.
|
364 |
| - if values.shape[1] == 0: |
| 386 | + if values.shape[0] == 0: |
365 | 387 | raise ValueError("Empty data passed with indices specified.")
|
366 | 388 |
|
367 |
| - passed = values.T.shape |
| 389 | + passed = values.shape |
368 | 390 | implied = (len(index), len(columns))
|
369 | 391 | raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}")
|
370 | 392 |
|
|
0 commit comments