|
7 | 7 |
|
8 | 8 | import numpy as np |
9 | 9 |
|
10 | | -from pandas import (date_range, notna, Series, Index, Float64Index, |
| 10 | +from pandas import (date_range, Series, Index, Float64Index, |
11 | 11 | Int64Index, UInt64Index, RangeIndex) |
12 | 12 |
|
13 | 13 | import pandas.util.testing as tm |
@@ -175,6 +175,18 @@ def test_modulo(self): |
175 | 175 | expected = Index(index.values % 2) |
176 | 176 | tm.assert_index_equal(index % 2, expected) |
177 | 177 |
|
| 178 | + @pytest.mark.parametrize('klass', [list, tuple, np.array, Series]) |
| 179 | + def test_where(self, klass): |
| 180 | + i = self.create_index() |
| 181 | + cond = [True] * len(i) |
| 182 | + expected = i |
| 183 | + result = i.where(klass(cond)) |
| 184 | + |
| 185 | + cond = [False] + [True] * (len(i) - 1) |
| 186 | + expected = Float64Index([i._na_value] + i[1:].tolist()) |
| 187 | + result = i.where(klass(cond)) |
| 188 | + tm.assert_index_equal(result, expected) |
| 189 | + |
178 | 190 |
|
179 | 191 | class TestFloat64Index(Numeric): |
180 | 192 | _holder = Float64Index |
@@ -658,30 +670,6 @@ def test_ufunc_coercions(self): |
658 | 670 | exp = Float64Index([0.5, 1., 1.5, 2., 2.5], name='x') |
659 | 671 | tm.assert_index_equal(result, exp) |
660 | 672 |
|
661 | | - def test_where(self): |
662 | | - i = self.create_index() |
663 | | - result = i.where(notna(i)) |
664 | | - expected = i |
665 | | - tm.assert_index_equal(result, expected) |
666 | | - |
667 | | - _nan = i._na_value |
668 | | - cond = [False] + [True] * len(i[1:]) |
669 | | - expected = Float64Index([_nan] + i[1:].tolist()) |
670 | | - result = i.where(cond) |
671 | | - tm.assert_index_equal(result, expected) |
672 | | - |
673 | | - def test_where_array_like(self): |
674 | | - i = self.create_index() |
675 | | - |
676 | | - _nan = i._na_value |
677 | | - cond = [False] + [True] * (len(i) - 1) |
678 | | - klasses = [list, tuple, np.array, pd.Series] |
679 | | - expected = Float64Index([_nan] + i[1:].tolist()) |
680 | | - |
681 | | - for klass in klasses: |
682 | | - result = i.where(klass(cond)) |
683 | | - tm.assert_index_equal(result, expected) |
684 | | - |
685 | 673 |
|
686 | 674 | class TestInt64Index(NumericInt): |
687 | 675 | _dtype = 'int64' |
|
0 commit comments