Skip to content

Commit f05a7cf

Browse files
committed
Remove .ix method, part 1
1 parent 46d88c1 commit f05a7cf

File tree

4 files changed

+3
-450
lines changed

4 files changed

+3
-450
lines changed

pandas/tests/frame/test_indexing.py

-79
Original file line numberDiff line numberDiff line change
@@ -393,85 +393,6 @@ def test_boolean_index_empty_corner(self):
393393
blah[k]
394394
blah[k] = 0
395395

396-
def test_getitem_ix_mixed_integer(self):
397-
df = DataFrame(
398-
np.random.randn(4, 3), index=[1, 10, "C", "E"], columns=[1, 2, 3]
399-
)
400-
401-
result = df.iloc[:-1]
402-
expected = df.loc[df.index[:-1]]
403-
assert_frame_equal(result, expected)
404-
405-
with catch_warnings(record=True):
406-
simplefilter("ignore", FutureWarning)
407-
result = df.ix[[1, 10]]
408-
expected = df.ix[Index([1, 10], dtype=object)]
409-
assert_frame_equal(result, expected)
410-
411-
# 11320
412-
df = pd.DataFrame(
413-
{
414-
"rna": (1.5, 2.2, 3.2, 4.5),
415-
-1000: [11, 21, 36, 40],
416-
0: [10, 22, 43, 34],
417-
1000: [0, 10, 20, 30],
418-
},
419-
columns=["rna", -1000, 0, 1000],
420-
)
421-
result = df[[1000]]
422-
expected = df.iloc[:, [3]]
423-
assert_frame_equal(result, expected)
424-
result = df[[-1000]]
425-
expected = df.iloc[:, [1]]
426-
assert_frame_equal(result, expected)
427-
428-
def test_getitem_setitem_ix_negative_integers(self, float_frame):
429-
with catch_warnings(record=True):
430-
simplefilter("ignore", FutureWarning)
431-
result = float_frame.ix[:, -1]
432-
assert_series_equal(result, float_frame["D"])
433-
434-
with catch_warnings(record=True):
435-
simplefilter("ignore", FutureWarning)
436-
result = float_frame.ix[:, [-1]]
437-
assert_frame_equal(result, float_frame[["D"]])
438-
439-
with catch_warnings(record=True):
440-
simplefilter("ignore", FutureWarning)
441-
result = float_frame.ix[:, [-1, -2]]
442-
assert_frame_equal(result, float_frame[["D", "C"]])
443-
444-
with catch_warnings(record=True):
445-
simplefilter("ignore", FutureWarning)
446-
float_frame.ix[:, [-1]] = 0
447-
assert (float_frame["D"] == 0).all()
448-
449-
df = DataFrame(np.random.randn(8, 4))
450-
# ix does label-based indexing when having an integer index
451-
msg = "\"None of [Int64Index([-1], dtype='int64')] are in the [index]\""
452-
with catch_warnings(record=True):
453-
simplefilter("ignore", FutureWarning)
454-
with pytest.raises(KeyError, match=re.escape(msg)):
455-
df.ix[[-1]]
456-
457-
msg = "\"None of [Int64Index([-1], dtype='int64')] are in the [columns]\""
458-
with catch_warnings(record=True):
459-
simplefilter("ignore", FutureWarning)
460-
with pytest.raises(KeyError, match=re.escape(msg)):
461-
df.ix[:, [-1]]
462-
463-
# #1942
464-
a = DataFrame(np.random.randn(20, 2), index=[chr(x + 65) for x in range(20)])
465-
with catch_warnings(record=True):
466-
simplefilter("ignore", FutureWarning)
467-
a.ix[-1] = a.ix[-2]
468-
469-
with catch_warnings(record=True):
470-
simplefilter("ignore", FutureWarning)
471-
assert_series_equal(a.ix[-1], a.ix[-2], check_names=False)
472-
assert a.ix[-1].name == "T"
473-
assert a.ix[-2].name == "S"
474-
475396
def test_getattr(self, float_frame):
476397
assert_series_equal(float_frame.A, float_frame["A"])
477398
msg = "'DataFrame' object has no attribute 'NONEXISTENT_NAME'"

pandas/tests/indexing/multiindex/test_slice.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212
from pandas.util import testing as tm
1313

1414

15-
@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning")
1615
class TestMultiIndexSlicers:
1716
def test_per_axis_per_level_getitem(self):
1817

1918
# GH6134
2019
# example test case
21-
ix = MultiIndex.from_product(
20+
midx = MultiIndex.from_product(
2221
[_mklbl("A", 5), _mklbl("B", 7), _mklbl("C", 4), _mklbl("D", 2)]
2322
)
24-
df = DataFrame(np.arange(len(ix.to_numpy())), index=ix)
23+
df = DataFrame(np.arange(len(midx.to_numpy())), index=midx)
2524

2625
result = df.loc[(slice("A1", "A3"), slice(None), ["C1", "C3"]), :]
2726
expected = df.loc[
@@ -98,7 +97,7 @@ def test_per_axis_per_level_getitem(self):
9897
tm.assert_frame_equal(result, expected)
9998

10099
# multi-level series
101-
s = Series(np.arange(len(ix.to_numpy())), index=ix)
100+
s = Series(np.arange(len(midx)), index=midx)
102101
result = s.loc["A1":"A3", :, ["C1", "C3"]]
103102
expected = s.loc[
104103
[
@@ -637,8 +636,6 @@ def test_multiindex_label_slicing_with_negative_step(self):
637636
def assert_slices_equivalent(l_slc, i_slc):
638637
tm.assert_series_equal(s.loc[l_slc], s.iloc[i_slc])
639638
tm.assert_series_equal(s[l_slc], s.iloc[i_slc])
640-
with catch_warnings(record=True):
641-
tm.assert_series_equal(s.ix[l_slc], s.iloc[i_slc])
642639

643640
assert_slices_equivalent(SLC[::-1], SLC[::-1])
644641

0 commit comments

Comments
 (0)