-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
TST/DEPR: remove .ix from tests\indexing\multiindex\test_loc.py #26451
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
Merged
jreback
merged 4 commits into
pandas-dev:master
from
simonjayhawkins:mi-test_loc-depr-ix
May 19, 2019
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import itertools | ||
from warnings import catch_warnings | ||
|
||
import numpy as np | ||
import pytest | ||
|
@@ -25,7 +24,6 @@ def frame_random_data_integer_multi_index(): | |
return DataFrame(np.random.randn(6, 2), index=index) | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") | ||
class TestMultiIndexLoc: | ||
|
||
def test_loc_getitem_series(self): | ||
|
@@ -84,54 +82,50 @@ def test_loc_getitem_array(self): | |
result = x.loc[scalar] | ||
tm.assert_series_equal(result, expected) | ||
|
||
def test_loc_multiindex(self): | ||
def test_loc_multiindex_labels(self): | ||
df = DataFrame(np.random.randn(3, 3), | ||
columns=[['i', 'i', 'j'], ['A', 'A', 'B']], | ||
index=[['i', 'i', 'j'], ['X', 'X', 'Y']]) | ||
|
||
mi_labels = DataFrame(np.random.randn(3, 3), | ||
columns=[['i', 'i', 'j'], ['A', 'A', 'B']], | ||
index=[['i', 'i', 'j'], ['X', 'X', 'Y']]) | ||
|
||
mi_int = DataFrame(np.random.randn(3, 3), | ||
columns=[[2, 2, 4], [6, 8, 10]], | ||
index=[[4, 4, 8], [8, 10, 12]]) | ||
|
||
# the first row | ||
rs = mi_labels.loc['i'] | ||
with catch_warnings(record=True): | ||
xp = mi_labels.ix['i'] | ||
tm.assert_frame_equal(rs, xp) | ||
# the first 2 rows | ||
expected = DataFrame( | ||
df.values[[0, 1]], index=['X', 'X'], columns=df.columns) | ||
result = df.loc['i'] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# 2nd (last) columns | ||
rs = mi_labels.loc[:, 'j'] | ||
with catch_warnings(record=True): | ||
xp = mi_labels.ix[:, 'j'] | ||
tm.assert_frame_equal(rs, xp) | ||
# 2nd (last) column | ||
expected = DataFrame(df.values[:, [2]], index=df.index, columns=['B']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same, don't directly use |
||
result = df.loc[:, 'j'] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# corner column | ||
rs = mi_labels.loc['j'].loc[:, 'j'] | ||
with catch_warnings(record=True): | ||
xp = mi_labels.ix['j'].ix[:, 'j'] | ||
tm.assert_frame_equal(rs, xp) | ||
# bottom right corner column | ||
expected = DataFrame(df.values[[2], [2]], index=['Y'], columns=['B']) | ||
result = df.loc['j'].loc[:, 'j'] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
# with a tuple | ||
rs = mi_labels.loc[('i', 'X')] | ||
with catch_warnings(record=True): | ||
xp = mi_labels.ix[('i', 'X')] | ||
tm.assert_frame_equal(rs, xp) | ||
expected = df.iloc[[0, 1]] | ||
result = df.loc[('i', 'X')] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
def test_loc_multiindex_ints(self): | ||
df = DataFrame(np.random.randn(3, 3), | ||
columns=[[2, 2, 4], [6, 8, 10]], | ||
index=[[4, 4, 8], [8, 10, 12]]) | ||
expected = DataFrame( | ||
df.values[[0, 1]], index=[8, 10], columns=df.columns) | ||
result = df.loc[4] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
rs = mi_int.loc[4] | ||
with catch_warnings(record=True): | ||
xp = mi_int.ix[4] | ||
tm.assert_frame_equal(rs, xp) | ||
def test_loc_multiindex_missing_label_raises(self): | ||
df = DataFrame(np.random.randn(3, 3), | ||
columns=[[2, 2, 4], [6, 8, 10]], | ||
index=[[4, 4, 8], [8, 10, 12]]) | ||
|
||
# missing label | ||
with pytest.raises(KeyError, match=r"^2$"): | ||
mi_int.loc[2] | ||
with catch_warnings(record=True): | ||
# GH 21593 | ||
with pytest.raises(KeyError, match=r"^2$"): | ||
mi_int.ix[2] | ||
df.loc[2] | ||
|
||
def test_loc_multiindex_too_many_dims(self): | ||
def test_loc_multiindex_too_many_dims_raises(self): | ||
# GH 14885 | ||
s = Series(range(8), index=MultiIndex.from_product( | ||
[['a', 'b'], ['c', 'd'], ['e', 'f']])) | ||
|
@@ -227,7 +221,6 @@ def test_loc_getitem_int_slice(self): | |
tm.assert_frame_equal(result, expected) | ||
|
||
result = df.loc[:, 10] | ||
# expected = df.ix[:,10] (this fails) | ||
expected = df[10] | ||
tm.assert_frame_equal(result, expected) | ||
|
||
|
@@ -309,17 +302,11 @@ def test_loc_getitem_duplicates_multiindex_missing_indexers(indexer, is_level1, | |
tm.assert_series_equal(result, expected) | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") | ||
@pytest.mark.parametrize('indexer', [ | ||
lambda s: s.loc[[(2000, 3, 10), (2000, 3, 13)]], | ||
lambda s: s.ix[[(2000, 3, 10), (2000, 3, 13)]] | ||
]) | ||
def test_series_loc_getitem_fancy( | ||
multiindex_year_month_day_dataframe_random_data, indexer): | ||
multiindex_year_month_day_dataframe_random_data): | ||
s = multiindex_year_month_day_dataframe_random_data['A'] | ||
expected = s.reindex(s.index[49:51]) | ||
|
||
result = indexer(s) | ||
result = s.loc[[(2000, 3, 10), (2000, 3, 13)]] | ||
tm.assert_series_equal(result, expected) | ||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
.iloc