-
-
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 48 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 |
---|---|---|
|
@@ -485,12 +485,12 @@ def getPeriodData(nper=None): | |
# make frame | ||
def makeTimeDataFrame(nper=None, freq="B"): | ||
data = getTimeSeriesData(nper, freq) | ||
return DataFrame(data) | ||
return DataFrame(data)._consolidate() | ||
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. This change should in theory no longer be needed? (assuming this was done to ensure consolidated dataframe when the default was changed to not copy, and thus result in non-consolidated dataframe) (and same for the 2 cases just below) |
||
|
||
|
||
def makeDataFrame() -> DataFrame: | ||
data = getSeriesData() | ||
return DataFrame(data) | ||
return DataFrame(data)._consolidate() | ||
|
||
|
||
def getMixedTypeDict(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -553,28 +553,28 @@ 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. |
||
): | ||
orig_copy = copy # GH#38939 | ||
copy = copy if copy is not None else 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.
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. we also redefine |
||
|
||
if data is None: | ||
data = {} | ||
copy = True | ||
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. Do you remember what's the reason this is added? (I would assume that if there is no data, copy=True or False shouldn't matter) 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. i dont recall off the top of my head. will revert and re-run tests to find out, and either remove or add a comment |
||
if dtype is not None: | ||
dtype = self._validate_dtype(dtype) | ||
|
||
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) | ||
copy = copy if copy is not None else 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. Alternatively can check |
||
if index is None and columns is None and dtype is None and copy is False: | ||
# GH#33357 fastpath | ||
NDFrame.__init__(self, data) | ||
return | ||
|
||
manager = get_option("mode.data_manager") | ||
|
||
|
@@ -584,7 +584,9 @@ 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 | ||
copy = orig_copy if orig_copy is not None else True | ||
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.