Skip to content

PERF: directly astype with numpy if series is already nansafe #8732

Closed
@jreback

Description

@jreback

from SO

so the null check is pretty cheap. if no nulls, then can just bypass nansafe an use the underlying numpy routine. should be a nice speedup.

``
In [13]: arr = np.random.randint(1,10,size=1000000)

In [14]: s = Series(arr)

In [15]: s.notnull().all()
Out[15]: True

In [16]: %timeit s.notnull().all()
1000 loops, best of 3: 1.35 ms per loop

In [17]: %timeit s.astype(str)
1 loops, best of 3: 2.52 s per loop

In [18]: %timeit s.values.astype(str)
10 loops, best of 3: 37.7 ms per loop

Metadata

Metadata

Assignees

No one assigned

    Labels

    PerformanceMemory or execution speed performanceStringsString extension data type and string data

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions