Skip to content

PERF: Fix performance regression in infer_dtype #30202

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 11 commits into from
Dec 23, 2019
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ Performance improvements
- Performance improvement when checking if values in a :class:`Categorical` are equal, equal or larger or larger than a given scalar.
The improvement is not present if checking if the :class:`Categorical` is less than or less than or equal than the scalar (:issue:`29820`)
- Performance improvement in :meth:`Index.equals` and :meth:`MultiIndex.equals` (:issue:`29134`)
- Performance improvement in :func:`infer_dtype` when ``skipna`` is ``True`` (:issue:`28814`)

.. _whatsnew_1000.bug_fixes:

Expand Down
6 changes: 3 additions & 3 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1259,16 +1259,16 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
# make contiguous
values = values.ravel()

if skipna:
values = values[~isnaobj(values)]

val = _try_infer_map(values)
if val is not None:
return val

if values.dtype != np.object_:
values = values.astype('O')

if skipna:
values = values[~isnaobj(values)]

n = len(values)
if n == 0:
return 'empty'
Expand Down