Skip to content

Remove ix, part 1 #28884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 0 additions & 79 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,85 +393,6 @@ def test_boolean_index_empty_corner(self):
blah[k]
blah[k] = 0

def test_getitem_ix_mixed_integer(self):
df = DataFrame(
np.random.randn(4, 3), index=[1, 10, "C", "E"], columns=[1, 2, 3]
)

result = df.iloc[:-1]
expected = df.loc[df.index[:-1]]
assert_frame_equal(result, expected)

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
result = df.ix[[1, 10]]
expected = df.ix[Index([1, 10], dtype=object)]
assert_frame_equal(result, expected)

# 11320
df = pd.DataFrame(
{
"rna": (1.5, 2.2, 3.2, 4.5),
-1000: [11, 21, 36, 40],
0: [10, 22, 43, 34],
1000: [0, 10, 20, 30],
},
columns=["rna", -1000, 0, 1000],
)
result = df[[1000]]
expected = df.iloc[:, [3]]
assert_frame_equal(result, expected)
result = df[[-1000]]
expected = df.iloc[:, [1]]
assert_frame_equal(result, expected)

def test_getitem_setitem_ix_negative_integers(self, float_frame):
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
result = float_frame.ix[:, -1]
assert_series_equal(result, float_frame["D"])

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
result = float_frame.ix[:, [-1]]
assert_frame_equal(result, float_frame[["D"]])

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
result = float_frame.ix[:, [-1, -2]]
assert_frame_equal(result, float_frame[["D", "C"]])

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
float_frame.ix[:, [-1]] = 0
assert (float_frame["D"] == 0).all()

df = DataFrame(np.random.randn(8, 4))
# ix does label-based indexing when having an integer index
msg = "\"None of [Int64Index([-1], dtype='int64')] are in the [index]\""
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
with pytest.raises(KeyError, match=re.escape(msg)):
df.ix[[-1]]

msg = "\"None of [Int64Index([-1], dtype='int64')] are in the [columns]\""
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
with pytest.raises(KeyError, match=re.escape(msg)):
df.ix[:, [-1]]

# #1942
a = DataFrame(np.random.randn(20, 2), index=[chr(x + 65) for x in range(20)])
with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
a.ix[-1] = a.ix[-2]

with catch_warnings(record=True):
simplefilter("ignore", FutureWarning)
assert_series_equal(a.ix[-1], a.ix[-2], check_names=False)
assert a.ix[-1].name == "T"
assert a.ix[-2].name == "S"

def test_getattr(self, float_frame):
assert_series_equal(float_frame.A, float_frame["A"])
msg = "'DataFrame' object has no attribute 'NONEXISTENT_NAME'"
Expand Down
9 changes: 3 additions & 6 deletions pandas/tests/indexing/multiindex/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@
from pandas.util import testing as tm


@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning")
class TestMultiIndexSlicers:
def test_per_axis_per_level_getitem(self):

# GH6134
# example test case
ix = MultiIndex.from_product(
midx = MultiIndex.from_product(
[_mklbl("A", 5), _mklbl("B", 7), _mklbl("C", 4), _mklbl("D", 2)]
)
df = DataFrame(np.arange(len(ix.to_numpy())), index=ix)
df = DataFrame(np.arange(len(midx)), index=midx)

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

# multi-level series
s = Series(np.arange(len(ix.to_numpy())), index=ix)
s = Series(np.arange(len(midx)), index=midx)
result = s.loc["A1":"A3", :, ["C1", "C3"]]
expected = s.loc[
[
Expand Down Expand Up @@ -637,8 +636,6 @@ def test_multiindex_label_slicing_with_negative_step(self):
def assert_slices_equivalent(l_slc, i_slc):
tm.assert_series_equal(s.loc[l_slc], s.iloc[i_slc])
tm.assert_series_equal(s[l_slc], s.iloc[i_slc])
with catch_warnings(record=True):
tm.assert_series_equal(s.ix[l_slc], s.iloc[i_slc])

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

Expand Down
Loading