Skip to content

Commit b6324be

Browse files
qwhelanjreback
authored andcommitted
PERF: O(n) speedup in any/all by re-enabling short-circuiting for bool case (#25070)
1 parent 34da8be commit b6324be

File tree

3 files changed

+243
-67
lines changed

3 files changed

+243
-67
lines changed

asv_bench/benchmarks/series_methods.py

+42
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,46 @@ def time_series_datetimeindex_repr(self):
201201
getattr(self.s, 'a', None)
202202

203203

204+
class All(object):
205+
206+
params = [[10**3, 10**6], ['fast', 'slow']]
207+
param_names = ['N', 'case']
208+
209+
def setup(self, N, case):
210+
val = case != 'fast'
211+
self.s = Series([val] * N)
212+
213+
def time_all(self, N, case):
214+
self.s.all()
215+
216+
217+
class Any(object):
218+
219+
params = [[10**3, 10**6], ['fast', 'slow']]
220+
param_names = ['N', 'case']
221+
222+
def setup(self, N, case):
223+
val = case == 'fast'
224+
self.s = Series([val] * N)
225+
226+
def time_any(self, N, case):
227+
self.s.any()
228+
229+
230+
class NanOps(object):
231+
232+
params = [['var', 'mean', 'median', 'max', 'min', 'sum', 'std', 'sem',
233+
'argmax', 'skew', 'kurt', 'prod'],
234+
[10**3, 10**6],
235+
['int8', 'int32', 'int64', 'float64']]
236+
param_names = ['func', 'N', 'dtype']
237+
238+
def setup(self, func, N, dtype):
239+
self.s = Series([1] * N, dtype=dtype)
240+
self.func = getattr(self.s, func)
241+
242+
def time_func(self, func, N, dtype):
243+
self.func()
244+
245+
204246
from .pandas_vb_common import setup # noqa: F401

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ Performance Improvements
248248
- Imporved performance of :meth:`IntervalIndex.is_monotonic`, :meth:`IntervalIndex.is_monotonic_increasing` and :meth:`IntervalIndex.is_monotonic_decreasing` by removing conversion to :class:`MultiIndex` (:issue:`24813`)
249249
- Improved performance of :meth:`DataFrame.to_csv` when writing datetime dtypes (:issue:`25708`)
250250
- Improved performance of :meth:`read_csv` by much faster parsing of ``MM/YYYY`` and ``DD/MM/YYYY`` datetime formats (:issue:`25922`)
251+
- Improved performance of nanops for dtypes that cannot store NaNs. Speedup is particularly prominent for :meth:`Series.all` and :meth:`Series.any` (:issue:`25070`)
251252

252253
.. _whatsnew_0250.bug_fixes:
253254

0 commit comments

Comments
 (0)