Skip to content

Commit

Permalink
BUG: df constructor not copying ea backed series (pandas-dev#53744)
Browse files Browse the repository at this point in the history
Co-authored-by: Joris Van den Bossche <jorisvandenbossche@gmail.com>
  • Loading branch information
phofl and jorisvandenbossche committed Jun 28, 2023
1 parent ee16656 commit 6b7225a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ Sparse

ExtensionArray
^^^^^^^^^^^^^^
- Bug in :class:`DataFrame` constructor not copying :class:`Series` with extension dtype when given in dict (:issue:`53744`)
- Bug in :class:`~arrays.ArrowExtensionArray` converting pandas non-nanosecond temporal objects from non-zero values to zero values (:issue:`53171`)
- Bug in :meth:`Series.quantile` for pyarrow temporal types raising ArrowInvalid (:issue:`52678`)
- Bug in :meth:`Series.rank` returning wrong order for small values with ``Float64`` dtype (:issue:`52471`)
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,11 @@ def dict_to_mgr(
x.copy()
if isinstance(x, ExtensionArray)
else x.copy(deep=True)
if isinstance(x, Index)
if (
isinstance(x, Index)
or isinstance(x, ABCSeries)
and is_1d_only_ea_dtype(x.dtype)
)
else x
for x in arrays
]
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2576,6 +2576,13 @@ def check_views(c_only: bool = False):
# TODO: we can check b[0] == 0 if we stop consolidating in
# setitem_with_indexer (except for datetimelike?)

def test_construct_from_dict_ea_series(self):
# GH#53744 - default of copy=True should also apply for Series with
# extension dtype
ser = Series([1, 2, 3], dtype="Int64")
df = DataFrame({"a": ser})
assert not np.shares_memory(ser.values._data, df["a"].values._data)

def test_from_series_with_name_with_columns(self):
# GH 7893
result = DataFrame(Series(1, name="foo"), columns=["bar"])
Expand Down

0 comments on commit 6b7225a

Please sign in to comment.