Skip to content

Commit 1706d83

Browse files
authored
PERF: avoid duplicate is_single_block check (#35034)
1 parent f6fb257 commit 1706d83

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

pandas/core/internals/managers.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -805,17 +805,17 @@ def as_array(
805805
# mutating the original object
806806
copy = copy or na_value is not lib.no_default
807807

808-
if self._is_single_block and self.blocks[0].is_extension:
809-
# Avoid implicit conversion of extension blocks to object
810-
arr = (
811-
self.blocks[0]
812-
.values.to_numpy(dtype=dtype, na_value=na_value)
813-
.reshape(self.blocks[0].shape)
814-
)
815-
elif self._is_single_block:
816-
arr = np.asarray(self.blocks[0].get_values())
817-
if dtype:
818-
arr = arr.astype(dtype, copy=False)
808+
if self._is_single_block:
809+
blk = self.blocks[0]
810+
if blk.is_extension:
811+
# Avoid implicit conversion of extension blocks to object
812+
arr = blk.values.to_numpy(dtype=dtype, na_value=na_value).reshape(
813+
blk.shape
814+
)
815+
else:
816+
arr = np.asarray(blk.get_values())
817+
if dtype:
818+
arr = arr.astype(dtype, copy=False)
819819
else:
820820
arr = self._interleave(dtype=dtype, na_value=na_value)
821821
# The underlying data was copied within _interleave

0 commit comments

Comments
 (0)