Skip to content

Commit 6e1c915

Browse files
committed
TST: Add tests of SparseArray.all
1 parent cc4776b commit 6e1c915

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

pandas/tests/sparse/test_array.py

+44
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,50 @@ def test_fillna_overlap(self):
655655

656656
class TestSparseArrayAnalytics(object):
657657

658+
@pytest.mark.parametrize('data,pos,neg', [
659+
([True, True, True], True, False),
660+
([1, 2, 1], 1, 0),
661+
([1.0, 2.0, 1.0], 1.0, 0.0)
662+
])
663+
def test_all(self, data, pos, neg):
664+
# GH 17570
665+
out = SparseArray(data).all()
666+
assert out
667+
668+
out = SparseArray(data, fill_value=pos).all()
669+
assert out
670+
671+
data[1] = neg
672+
out = SparseArray(data).all()
673+
assert not out
674+
675+
out = SparseArray(data, fill_value=pos).all()
676+
assert not out
677+
678+
@pytest.mark.parametrize('data,pos,neg', [
679+
([True, True, True], True, False),
680+
([1, 2, 1], 1, 0),
681+
([1.0, 2.0, 1.0], 1.0, 0.0)
682+
])
683+
def test_numpy_all(self, data, pos, neg):
684+
# GH 17570
685+
out = np.all(SparseArray(data))
686+
assert out
687+
688+
out = np.all(SparseArray(data, fill_value=pos))
689+
assert out
690+
691+
data[1] = neg
692+
out = np.all(SparseArray(data))
693+
assert not out
694+
695+
out = np.all(SparseArray(data, fill_value=pos))
696+
assert not out
697+
698+
msg = "the 'out' parameter is not supported"
699+
tm.assert_raises_regex(ValueError, msg, np.all,
700+
SparseArray(data), out=out)
701+
658702
def test_sum(self):
659703
data = np.arange(10).astype(float)
660704
out = SparseArray(data).sum()

0 commit comments

Comments
 (0)