|
35 | 35 | )
|
36 | 36 | from pandas.core.dtypes.common import (
|
37 | 37 | is_1d_only_ea_dtype,
|
38 |
| - is_datetime64tz_dtype, |
39 | 38 | is_datetime_or_timedelta_dtype,
|
40 | 39 | is_dtype_equal,
|
41 | 40 | is_extension_array_dtype,
|
|
44 | 43 | is_named_tuple,
|
45 | 44 | is_object_dtype,
|
46 | 45 | )
|
47 |
| -from pandas.core.dtypes.dtypes import ExtensionDtype |
48 | 46 | from pandas.core.dtypes.generic import (
|
49 | 47 | ABCDataFrame,
|
50 | 48 | ABCSeries,
|
@@ -475,23 +473,16 @@ def dict_to_mgr(
|
475 | 473 | keys = list(data.keys())
|
476 | 474 | columns = Index(keys)
|
477 | 475 | arrays = [com.maybe_iterable_to_list(data[k]) for k in keys]
|
478 |
| - # GH#24096 need copy to be deep for datetime64tz case |
479 |
| - # TODO: See if we can avoid these copies |
480 | 476 | arrays = [arr if not isinstance(arr, Index) else arr._data for arr in arrays]
|
481 |
| - arrays = [ |
482 |
| - arr if not is_datetime64tz_dtype(arr) else arr.copy() for arr in arrays |
483 |
| - ] |
484 | 477 |
|
485 | 478 | if copy:
|
486 |
| - # arrays_to_mgr (via form_blocks) won't make copies for EAs |
487 |
| - # dtype attr check to exclude EADtype-castable strs |
488 |
| - arrays = [ |
489 |
| - x |
490 |
| - if not hasattr(x, "dtype") or not isinstance(x.dtype, ExtensionDtype) |
491 |
| - else x.copy() |
492 |
| - for x in arrays |
493 |
| - ] |
494 |
| - # TODO: can we get rid of the dt64tz special case above? |
| 479 | + if typ == "block": |
| 480 | + # We only need to copy arrays that will not get consolidated, i.e. |
| 481 | + # only EA arrays |
| 482 | + arrays = [x.copy() if isinstance(x, ExtensionArray) else x for x in arrays] |
| 483 | + else: |
| 484 | + # dtype check to exclude e.g. range objects, scalars |
| 485 | + arrays = [x.copy() if hasattr(x, "dtype") else x for x in arrays] |
495 | 486 |
|
496 | 487 | return arrays_to_mgr(arrays, columns, index, dtype=dtype, typ=typ, consolidate=copy)
|
497 | 488 |
|
|
0 commit comments