Skip to content

Commit 2b50039

Browse files
phoflmroeschke
andauthored
PERF: Improve performance for astype is view (#57478)
* PERF: Improve performance for astype is view * Update * Update * Fixup * Update astype.py * Update astype.py --------- Co-authored-by: Matthew Roeschke <[email protected]>
1 parent e0d2605 commit 2b50039

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pandas/core/dtypes/astype.py

+5
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ def astype_is_view(dtype: DtypeObj, new_dtype: DtypeObj) -> bool:
257257
-------
258258
True if new data is a view or not guaranteed to be a copy, False otherwise
259259
"""
260+
if dtype.kind in "iufb" and dtype.kind == new_dtype.kind:
261+
# fastpath for numeric dtypes
262+
if hasattr(dtype, "itemsize") and hasattr(new_dtype, "itemsize"):
263+
return dtype.itemsize == new_dtype.itemsize # pyright: ignore[reportAttributeAccessIssue]
264+
260265
if isinstance(dtype, np.dtype) and not isinstance(new_dtype, np.dtype):
261266
new_dtype, dtype = dtype, new_dtype
262267

0 commit comments

Comments
 (0)