-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
[ArrayManager] DataFrame constructors #39991
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 4 commits
61983d8
1d0315f
ffc8314
46e73c8
3e108df
854bb17
8726d42
6e17183
8096665
aef4cc8
9c0a3d6
1eb5cb7
0992e67
936b290
54d36ab
c56ffa8
164387c
143b572
6166927
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 |
---|---|---|
|
@@ -563,41 +563,57 @@ def __init__( | |
if isinstance(data, DataFrame): | ||
data = data._mgr | ||
|
||
if isinstance(data, (BlockManager, ArrayManager)): | ||
if index is None and columns is None and dtype is None and copy is False: | ||
# GH#33357 fastpath | ||
NDFrame.__init__(self, data) | ||
return | ||
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 | ||
|
||
manager = get_option("mode.data_manager") | ||
|
||
if isinstance(data, (BlockManager, ArrayManager)): | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
mgr = self._init_mgr( | ||
data, axes={"index": index, "columns": columns}, dtype=dtype, copy=copy | ||
) | ||
|
||
elif isinstance(data, dict): | ||
mgr = init_dict(data, index, columns, dtype=dtype) | ||
mgr = init_dict(data, index, columns, dtype=dtype, typ=manager) | ||
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 rename typ -> manager? 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. Note this is the same keyword as I use for Alternatively, we could make the 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. ok yeah +1 on the rename (followon ok ) and anything to make the keyword more obvious 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. -> #40074 |
||
elif isinstance(data, ma.MaskedArray): | ||
import numpy.ma.mrecords as mrecords | ||
|
||
# masked recarray | ||
if isinstance(data, mrecords.MaskedRecords): | ||
mgr = masked_rec_array_to_mgr(data, index, columns, dtype, copy) | ||
mgr = masked_rec_array_to_mgr( | ||
data, index, columns, dtype, copy, typ=manager | ||
) | ||
|
||
# a masked array | ||
else: | ||
data = sanitize_masked_array(data) | ||
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy) | ||
mgr = init_ndarray( | ||
data, index, columns, dtype=dtype, copy=copy, typ=manager | ||
) | ||
|
||
elif isinstance(data, (np.ndarray, Series, Index)): | ||
if data.dtype.names: | ||
data_columns = list(data.dtype.names) | ||
data = {k: data[k] for k in data_columns} | ||
if columns is None: | ||
columns = data_columns | ||
mgr = init_dict(data, index, columns, dtype=dtype) | ||
mgr = init_dict(data, index, columns, dtype=dtype, typ=manager) | ||
elif getattr(data, "name", None) is not None: | ||
mgr = init_dict({data.name: data}, index, columns, dtype=dtype) | ||
mgr = init_dict( | ||
{data.name: data}, index, columns, dtype=dtype, typ=manager | ||
) | ||
else: | ||
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy) | ||
mgr = init_ndarray( | ||
data, index, columns, dtype=dtype, copy=copy, typ=manager | ||
) | ||
|
||
# For data is list-like, or Iterable (will consume into list) | ||
elif is_list_like(data): | ||
|
@@ -610,11 +626,15 @@ def __init__( | |
arrays, columns, index = nested_data_to_arrays( | ||
data, columns, index, dtype | ||
) | ||
mgr = arrays_to_mgr(arrays, columns, index, columns, dtype=dtype) | ||
mgr = arrays_to_mgr( | ||
arrays, columns, index, columns, dtype=dtype, typ=manager | ||
) | ||
else: | ||
mgr = init_ndarray(data, index, columns, dtype=dtype, copy=copy) | ||
mgr = init_ndarray( | ||
data, index, columns, dtype=dtype, copy=copy, typ=manager | ||
) | ||
else: | ||
mgr = init_dict({}, index, columns, dtype=dtype) | ||
mgr = init_dict({}, index, columns, dtype=dtype, typ=manager) | ||
# For data is scalar | ||
else: | ||
if index is None or columns is None: | ||
|
@@ -631,18 +651,19 @@ def __init__( | |
construct_1d_arraylike_from_scalar(data, len(index), dtype) | ||
for _ in range(len(columns)) | ||
] | ||
mgr = arrays_to_mgr(values, columns, index, columns, dtype=None) | ||
mgr = arrays_to_mgr( | ||
values, columns, index, columns, dtype=None, typ=manager | ||
) | ||
else: | ||
values = construct_2d_arraylike_from_scalar( | ||
data, len(index), len(columns), dtype, copy | ||
) | ||
|
||
mgr = init_ndarray( | ||
values, index, columns, dtype=values.dtype, copy=False | ||
values, index, columns, dtype=values.dtype, copy=False, typ=manager | ||
) | ||
|
||
# ensure correct Manager type according to settings | ||
manager = get_option("mode.data_manager") | ||
mgr = mgr_to_mgr(mgr, typ=manager) | ||
|
||
NDFrame.__init__(self, mgr) | ||
|
@@ -1970,7 +1991,8 @@ def from_records( | |
arr_columns = arr_columns.drop(arr_exclude) | ||
columns = columns.drop(exclude) | ||
|
||
mgr = arrays_to_mgr(arrays, arr_columns, result_index, columns) | ||
manager = get_option("mode.data_manager") | ||
mgr = arrays_to_mgr(arrays, arr_columns, result_index, columns, typ=manager) | ||
|
||
return cls(mgr) | ||
|
||
|
@@ -2177,13 +2199,15 @@ def _from_arrays( | |
if dtype is not None: | ||
dtype = pandas_dtype(dtype) | ||
|
||
manager = get_option("mode.data_manager") | ||
mgr = arrays_to_mgr( | ||
arrays, | ||
columns, | ||
index, | ||
columns, | ||
dtype=dtype, | ||
verify_integrity=verify_integrity, | ||
typ=manager, | ||
) | ||
return cls(mgr) | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.