Skip to content

Commit 6100425

Browse files
authored
PERF: creating string Series/Arrays from sequence with many strings (#36304)
1 parent cb58dbb commit 6100425

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

doc/source/whatsnew/v1.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ Deprecations
205205
Performance improvements
206206
~~~~~~~~~~~~~~~~~~~~~~~~
207207

208+
- Performance improvements when creating Series with dtype `str` or :class:`StringDtype` from array with many string elements (:issue:`36304`)
208209
- Performance improvement in :meth:`GroupBy.agg` with the ``numba`` engine (:issue:`35759`)
209210
-
210211

pandas/_libs/lib.pyx

+4
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,10 @@ cpdef ndarray[object] ensure_string_array(
655655

656656
for i in range(n):
657657
val = result[i]
658+
659+
if isinstance(val, str):
660+
continue
661+
658662
if not checknull(val):
659663
result[i] = str(val)
660664
else:

0 commit comments

Comments
 (0)