Skip to content

Commit f5b4f6b

Browse files
committed
TST: Add tests of SparseArray.any
1 parent 9e506a4 commit f5b4f6b

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
@@ -699,6 +699,50 @@ def test_numpy_all(self, data, pos, neg):
699699
tm.assert_raises_regex(ValueError, msg, np.all,
700700
SparseArray(data), out=out)
701701

702+
@pytest.mark.parametrize('data,pos,neg', [
703+
([False, True, False], True, False),
704+
([0, 2, 0], 2, 0),
705+
([0.0, 2.0, 0.0], 2.0, 0.0)
706+
])
707+
def test_any(self, data, pos, neg):
708+
# GH 17570
709+
out = SparseArray(data).any()
710+
assert out
711+
712+
out = SparseArray(data, fill_value=pos).any()
713+
assert out
714+
715+
data[1] = neg
716+
out = SparseArray(data).any()
717+
assert not out
718+
719+
out = SparseArray(data, fill_value=pos).any()
720+
assert not out
721+
722+
@pytest.mark.parametrize('data,pos,neg', [
723+
([False, True, False], True, False),
724+
([0, 2, 0], 2, 0),
725+
([0.0, 2.0, 0.0], 2.0, 0.0)
726+
])
727+
def test_numpy_any(self, data, pos, neg):
728+
# GH 17570
729+
out = np.any(SparseArray(data))
730+
assert out
731+
732+
out = np.any(SparseArray(data, fill_value=pos))
733+
assert out
734+
735+
data[1] = neg
736+
out = np.any(SparseArray(data))
737+
assert not out
738+
739+
out = np.any(SparseArray(data, fill_value=pos))
740+
assert not out
741+
742+
msg = "the 'out' parameter is not supported"
743+
tm.assert_raises_regex(ValueError, msg, np.any,
744+
SparseArray(data), out=out)
745+
702746
def test_sum(self):
703747
data = np.arange(10).astype(float)
704748
out = SparseArray(data).sum()

0 commit comments

Comments
 (0)