Skip to content

PERF: avoid duplicate is_single_block check #35034

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

Merged
merged 2 commits into from
Jun 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions pandas/core/internals/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,17 +805,17 @@ def as_array(
# mutating the original object
copy = copy or na_value is not lib.no_default

if self._is_single_block and self.blocks[0].is_extension:
# Avoid implicit conversion of extension blocks to object
arr = (
self.blocks[0]
.values.to_numpy(dtype=dtype, na_value=na_value)
.reshape(self.blocks[0].shape)
)
elif self._is_single_block:
arr = np.asarray(self.blocks[0].get_values())
if dtype:
arr = arr.astype(dtype, copy=False)
if self._is_single_block:
blk = self.blocks[0]
if blk.is_extension:
# Avoid implicit conversion of extension blocks to object
arr = blk.values.to_numpy(dtype=dtype, na_value=na_value).reshape(
blk.shape
)
else:
arr = np.asarray(blk.get_values())
if dtype:
arr = arr.astype(dtype, copy=False)
else:
arr = self._interleave(dtype=dtype, na_value=na_value)
# The underlying data was copied within _interleave
Expand Down