Skip to content

Commit 39492e9

Browse files
jorisvandenbosschemroeschke
authored andcommitted
PERF: DataFrame(ndarray) constructor ensure to copy to column-major layout (pandas-dev#57459)
* PERF: DataFrame(ndarray) constructor ensure to copy to column-major layout * fixup --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent f3f59c8 commit 39492e9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pandas/core/internals/construction.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,12 @@ def ndarray_to_mgr(
250250

251251
elif isinstance(values, (np.ndarray, ExtensionArray)):
252252
# drop subclass info
253-
_copy = (
254-
copy if (dtype is None or astype_is_view(values.dtype, dtype)) else False
255-
)
256-
values = np.array(values, copy=_copy)
253+
if copy and (dtype is None or astype_is_view(values.dtype, dtype)):
254+
# only force a copy now if copy=True was requested
255+
# and a subsequent `astype` will not already result in a copy
256+
values = np.array(values, copy=True, order="F")
257+
else:
258+
values = np.array(values, copy=False)
257259
values = _ensure_2d(values)
258260

259261
else:

0 commit comments

Comments
 (0)