-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
API: honor copy=True when passing dict to DataFrame #38939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cbc97f0
a135d96
5c94129
d653c54
e71e319
cafa718
c706ad6
3f9195e
1cba671
396daba
11ae1c9
b505267
a1e9b68
b70d997
09213e0
e895de0
31bda58
37a2c0c
b93d7d5
aa667a6
185cd99
701356f
948ac67
46f2fcf
0bbfec0
590c820
17a693c
fb8f32d
7835184
2136289
187499c
6f30beb
e80d57c
b0a6abd
bf942ae
95e30a5
510f697
48e359e
048e826
6a9c9f0
a17c728
5b3d419
f961378
fcee44b
0c60ae8
1468e59
b6d8b70
8b66b11
54cacfc
5ea7a75
e11ea68
65d01c7
41c4e7a
7260a72
52344bb
3ddc3d3
e6bae0f
7cab084
e8e3d84
5c44953
e32f630
abd890a
1b7f7ca
b326b5f
b7aed5d
4d20fe7
ad5485a
6bed6ac
98b6dff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -476,8 +476,12 @@ class DataFrame(NDFrame, OpsMixin): | |
RangeIndex (0, 1, 2, ..., n) if no column labels are provided. | ||
dtype : dtype, default None | ||
Data type to force. Only a single dtype is allowed. If None, infer. | ||
copy : bool, default False | ||
Copy data from inputs. Only affects DataFrame / 2d ndarray input. | ||
copy : bool or None, default None | ||
Copy data from inputs. | ||
For dict data, the default of None behaves like ``copy=True``. For DataFrame | ||
or 2d ndarray input, the default of None behaves like ``copy=False``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a versionchanged 1.3 |
||
|
||
.. versionchanged:: 1.3.0 | ||
|
||
See Also | ||
-------- | ||
|
@@ -555,8 +559,16 @@ def __init__( | |
index: Optional[Axes] = None, | ||
columns: Optional[Axes] = None, | ||
dtype: Optional[Dtype] = None, | ||
copy: bool = False, | ||
copy: Optional[bool] = None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you update the docstring above for this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good idea, will do. |
||
): | ||
|
||
if copy is None: | ||
if isinstance(data, dict) or data is None: | ||
# retain pre-GH#38939 default behavior | ||
copy = True | ||
else: | ||
copy = False | ||
|
||
if data is None: | ||
data = {} | ||
if dtype is not None: | ||
|
@@ -565,18 +577,13 @@ def __init__( | |
if isinstance(data, DataFrame): | ||
data = data._mgr | ||
|
||
# first check if a Manager is passed without any other arguments | ||
# -> use fastpath (without checking Manager type) | ||
if ( | ||
index is None | ||
and columns is None | ||
and dtype is None | ||
and copy is False | ||
and isinstance(data, (BlockManager, ArrayManager)) | ||
): | ||
# GH#33357 fastpath | ||
NDFrame.__init__(self, data) | ||
return | ||
if isinstance(data, (BlockManager, ArrayManager)): | ||
# first check if a Manager is passed without any other arguments | ||
# -> use fastpath (without checking Manager type) | ||
if index is None and columns is None and dtype is None and not copy: | ||
# GH#33357 fastpath | ||
NDFrame.__init__(self, data) | ||
return | ||
|
||
manager = get_option("mode.data_manager") | ||
|
||
|
@@ -586,7 +593,8 @@ def __init__( | |
) | ||
|
||
elif isinstance(data, dict): | ||
mgr = dict_to_mgr(data, index, columns, dtype=dtype, typ=manager) | ||
# GH#38939 de facto copy defaults to False only in non-dict cases | ||
mgr = dict_to_mgr(data, index, columns, dtype=dtype, copy=copy, typ=manager) | ||
elif isinstance(data, ma.MaskedArray): | ||
import numpy.ma.mrecords as mrecords | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.