Skip to content

Commit b99e84f

Browse files
simonjayhawkinsjreback
authored andcommitted
TST/DEPR: remove .ix from tests\indexing\multiindex\test_loc.py (#26451)
1 parent e4f727b commit b99e84f

File tree

2 files changed

+52
-50
lines changed

2 files changed

+52
-50
lines changed

pandas/tests/indexing/multiindex/test_ix.py

+17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from warnings import catch_warnings, simplefilter
22

3+
import numpy as np
34
import pytest
45

56
from pandas.errors import PerformanceWarning
@@ -53,3 +54,19 @@ def test_ix_general(self):
5354
names=['col', 'year'])
5455
expected = DataFrame({'amount': [222, 333, 444]}, index=index)
5556
tm.assert_frame_equal(res, expected)
57+
58+
def test_ix_multiindex_missing_label_raises(self):
59+
# GH 21593
60+
df = DataFrame(np.random.randn(3, 3),
61+
columns=[[2, 2, 4], [6, 8, 10]],
62+
index=[[4, 4, 8], [8, 10, 12]])
63+
64+
with pytest.raises(KeyError, match=r"^2$"):
65+
df.ix[2]
66+
67+
def test_series_ix_getitem_fancy(
68+
self, multiindex_year_month_day_dataframe_random_data):
69+
s = multiindex_year_month_day_dataframe_random_data['A']
70+
expected = s.reindex(s.index[49:51])
71+
result = s.ix[[(2000, 3, 10), (2000, 3, 13)]]
72+
tm.assert_series_equal(result, expected)

pandas/tests/indexing/multiindex/test_loc.py

+35-50
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import itertools
2-
from warnings import catch_warnings
32

43
import numpy as np
54
import pytest
@@ -25,7 +24,6 @@ def frame_random_data_integer_multi_index():
2524
return DataFrame(np.random.randn(6, 2), index=index)
2625

2726

28-
@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning")
2927
class TestMultiIndexLoc:
3028

3129
def test_loc_getitem_series(self):
@@ -84,54 +82,48 @@ def test_loc_getitem_array(self):
8482
result = x.loc[scalar]
8583
tm.assert_series_equal(result, expected)
8684

87-
def test_loc_multiindex(self):
85+
def test_loc_multiindex_labels(self):
86+
df = DataFrame(np.random.randn(3, 3),
87+
columns=[['i', 'i', 'j'], ['A', 'A', 'B']],
88+
index=[['i', 'i', 'j'], ['X', 'X', 'Y']])
8889

89-
mi_labels = DataFrame(np.random.randn(3, 3),
90-
columns=[['i', 'i', 'j'], ['A', 'A', 'B']],
91-
index=[['i', 'i', 'j'], ['X', 'X', 'Y']])
92-
93-
mi_int = DataFrame(np.random.randn(3, 3),
94-
columns=[[2, 2, 4], [6, 8, 10]],
95-
index=[[4, 4, 8], [8, 10, 12]])
96-
97-
# the first row
98-
rs = mi_labels.loc['i']
99-
with catch_warnings(record=True):
100-
xp = mi_labels.ix['i']
101-
tm.assert_frame_equal(rs, xp)
90+
# the first 2 rows
91+
expected = df.iloc[[0, 1]].droplevel(0)
92+
result = df.loc['i']
93+
tm.assert_frame_equal(result, expected)
10294

103-
# 2nd (last) columns
104-
rs = mi_labels.loc[:, 'j']
105-
with catch_warnings(record=True):
106-
xp = mi_labels.ix[:, 'j']
107-
tm.assert_frame_equal(rs, xp)
95+
# 2nd (last) column
96+
expected = df.iloc[:, [2]].droplevel(0, axis=1)
97+
result = df.loc[:, 'j']
98+
tm.assert_frame_equal(result, expected)
10899

109-
# corner column
110-
rs = mi_labels.loc['j'].loc[:, 'j']
111-
with catch_warnings(record=True):
112-
xp = mi_labels.ix['j'].ix[:, 'j']
113-
tm.assert_frame_equal(rs, xp)
100+
# bottom right corner
101+
expected = df.iloc[[2], [2]].droplevel(0).droplevel(0, axis=1)
102+
result = df.loc['j'].loc[:, 'j']
103+
tm.assert_frame_equal(result, expected)
114104

115105
# with a tuple
116-
rs = mi_labels.loc[('i', 'X')]
117-
with catch_warnings(record=True):
118-
xp = mi_labels.ix[('i', 'X')]
119-
tm.assert_frame_equal(rs, xp)
106+
expected = df.iloc[[0, 1]]
107+
result = df.loc[('i', 'X')]
108+
tm.assert_frame_equal(result, expected)
109+
110+
def test_loc_multiindex_ints(self):
111+
df = DataFrame(np.random.randn(3, 3),
112+
columns=[[2, 2, 4], [6, 8, 10]],
113+
index=[[4, 4, 8], [8, 10, 12]])
114+
expected = df.iloc[[0, 1]].droplevel(0)
115+
result = df.loc[4]
116+
tm.assert_frame_equal(result, expected)
120117

121-
rs = mi_int.loc[4]
122-
with catch_warnings(record=True):
123-
xp = mi_int.ix[4]
124-
tm.assert_frame_equal(rs, xp)
118+
def test_loc_multiindex_missing_label_raises(self):
119+
df = DataFrame(np.random.randn(3, 3),
120+
columns=[[2, 2, 4], [6, 8, 10]],
121+
index=[[4, 4, 8], [8, 10, 12]])
125122

126-
# missing label
127123
with pytest.raises(KeyError, match=r"^2$"):
128-
mi_int.loc[2]
129-
with catch_warnings(record=True):
130-
# GH 21593
131-
with pytest.raises(KeyError, match=r"^2$"):
132-
mi_int.ix[2]
124+
df.loc[2]
133125

134-
def test_loc_multiindex_too_many_dims(self):
126+
def test_loc_multiindex_too_many_dims_raises(self):
135127
# GH 14885
136128
s = Series(range(8), index=MultiIndex.from_product(
137129
[['a', 'b'], ['c', 'd'], ['e', 'f']]))
@@ -227,7 +219,6 @@ def test_loc_getitem_int_slice(self):
227219
tm.assert_frame_equal(result, expected)
228220

229221
result = df.loc[:, 10]
230-
# expected = df.ix[:,10] (this fails)
231222
expected = df[10]
232223
tm.assert_frame_equal(result, expected)
233224

@@ -309,17 +300,11 @@ def test_loc_getitem_duplicates_multiindex_missing_indexers(indexer, is_level1,
309300
tm.assert_series_equal(result, expected)
310301

311302

312-
@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning")
313-
@pytest.mark.parametrize('indexer', [
314-
lambda s: s.loc[[(2000, 3, 10), (2000, 3, 13)]],
315-
lambda s: s.ix[[(2000, 3, 10), (2000, 3, 13)]]
316-
])
317303
def test_series_loc_getitem_fancy(
318-
multiindex_year_month_day_dataframe_random_data, indexer):
304+
multiindex_year_month_day_dataframe_random_data):
319305
s = multiindex_year_month_day_dataframe_random_data['A']
320306
expected = s.reindex(s.index[49:51])
321-
322-
result = indexer(s)
307+
result = s.loc[[(2000, 3, 10), (2000, 3, 13)]]
323308
tm.assert_series_equal(result, expected)
324309

325310

0 commit comments

Comments
 (0)