Skip to content

Commit 9bf09ad

Browse files
authored
REF: fast_xs avoid object dtype (#43203)
1 parent 1009a7d commit 9bf09ad

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

pandas/core/internals/managers.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -941,23 +941,18 @@ def fast_xs(self, loc: int) -> ArrayLike:
941941

942942
n = len(self)
943943
if isinstance(dtype, ExtensionDtype):
944-
# we'll eventually construct an ExtensionArray.
945-
result = np.empty(n, dtype=object)
946-
# TODO: let's just use dtype.empty?
944+
cls = dtype.construct_array_type()
945+
result = cls._empty((n,), dtype=dtype)
947946
else:
948947
result = np.empty(n, dtype=dtype)
949-
950-
result = ensure_wrapped_if_datetimelike(result)
948+
result = ensure_wrapped_if_datetimelike(result)
951949

952950
for blk in self.blocks:
953951
# Such assignment may incorrectly coerce NaT to None
954952
# result[blk.mgr_locs] = blk._slice((slice(None), loc))
955953
for i, rl in enumerate(blk.mgr_locs):
956954
result[rl] = blk.iget((i, loc))
957955

958-
if isinstance(dtype, ExtensionDtype):
959-
result = dtype.construct_array_type()._from_sequence(result, dtype=dtype)
960-
961956
return result
962957

963958
def iget(self, i: int) -> SingleBlockManager:

0 commit comments

Comments
 (0)