Skip to content

Commit 9240439

Browse files
BeforeFlightjreback
authored andcommitted
ENH: maybe_convert_objects seen NaT speed-up (#27300)
1 parent c64c9cb commit 9240439

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

asv_bench/benchmarks/algorithms.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import numpy as np
44

5+
from pandas._libs import lib
6+
57
import pandas as pd
68
from pandas.util import testing as tm
79

@@ -13,6 +15,19 @@
1315
pass
1416

1517

18+
class MaybeConvertObjects:
19+
def setup(self):
20+
N = 10 ** 5
21+
22+
data = list(range(N))
23+
data[0] = pd.NaT
24+
data = np.array(data)
25+
self.data = data
26+
27+
def time_maybe_convert_objects(self):
28+
lib.maybe_convert_objects(self.data)
29+
30+
1631
class Factorize:
1732

1833
params = [[True, False], ["int", "uint", "float", "string"]]

doc/source/whatsnew/v0.25.0.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,6 @@ Performance improvements
940940
- For :meth:`to_datetime` changed default value of cache parameter to ``True`` (:issue:`26043`)
941941
- Improved performance of :class:`DatetimeIndex` and :class:`PeriodIndex` slicing given non-unique, monotonic data (:issue:`27136`).
942942
943-
944943
.. _whatsnew_0250.bug_fixes:
945944
946945
Bug fixes

pandas/_libs/lib.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,7 @@ def maybe_convert_objects(ndarray[object] objects, bint try_float=0,
19551955
seen.timedelta_ = 1
19561956
if not (convert_datetime or convert_timedelta):
19571957
seen.object_ = 1
1958+
break
19581959
elif util.is_bool_object(val):
19591960
seen.bool_ = 1
19601961
bools[i] = val

0 commit comments

Comments
 (0)