Skip to content

Commit cc4776b

Browse files
committed
BUG: Add SparseArray.all
1 parent cbb090f commit cc4776b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pandas/compat/numpy/function.py

+6
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ def validate_cum_func_with_skipna(skipna, args, kwargs, name):
184184
return skipna
185185

186186

187+
ALLANY_DEFAULTS = OrderedDict()
188+
ALLANY_DEFAULTS['dtype'] = None
189+
ALLANY_DEFAULTS['out'] = None
190+
validate_all = CompatValidator(ALLANY_DEFAULTS, fname='all',
191+
method='both', max_fname_arg_count=1)
192+
187193
LOGICAL_FUNC_DEFAULTS = dict(out=None)
188194
validate_logical_func = CompatValidator(LOGICAL_FUNC_DEFAULTS, method='kwargs')
189195

pandas/core/sparse/array.py

+21
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,27 @@ def fillna(self, value, downcast=None):
614614
return self._simple_new(new_values, self.sp_index,
615615
fill_value=fill_value)
616616

617+
def all(self, axis=0, *args, **kwargs):
618+
"""
619+
Tests whether all elements evaluate True
620+
621+
Returns
622+
-------
623+
all : bool
624+
625+
See Also
626+
--------
627+
numpy.all
628+
"""
629+
nv.validate_all(args, kwargs)
630+
631+
values = self.sp_values
632+
633+
if len(values) != len(self) and not np.all(self.fill_value):
634+
return False
635+
636+
return values.all()
637+
617638
def sum(self, axis=0, *args, **kwargs):
618639
"""
619640
Sum of non-NA/null values

0 commit comments

Comments
 (0)