From b208738dd264873567ca2fa78a18731d17baa546 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 23 Jul 2019 02:40:15 +0100 Subject: [PATCH] DEPR: remove .ix tests from tests/indexing/test_floats.py --- pandas/tests/indexing/test_floats.py | 150 +++++++-------------------- 1 file changed, 39 insertions(+), 111 deletions(-) diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 78ff6580bb1e1..56a78081bc624 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -1,5 +1,3 @@ -from warnings import catch_warnings - import numpy as np import pytest @@ -7,8 +5,6 @@ import pandas.util.testing as tm from pandas.util.testing import assert_almost_equal, assert_series_equal -ignore_ix = pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") - class TestFloatIndexers: def check(self, result, original, indexer, getitem): @@ -62,7 +58,6 @@ def test_scalar_error(self): with pytest.raises(TypeError, match=msg): s.iloc[3.0] = 0 - @ignore_ix def test_scalar_non_numeric(self): # GH 4892 @@ -86,11 +81,7 @@ def test_scalar_non_numeric(self): ]: # getting - for idxr, getitem in [ - (lambda x: x.ix, False), - (lambda x: x.iloc, False), - (lambda x: x, True), - ]: + for idxr, getitem in [(lambda x: x.iloc, False), (lambda x: x, True)]: # gettitem on a DataFrame is a KeyError as it is indexing # via labels on the columns @@ -106,9 +97,8 @@ def test_scalar_non_numeric(self): "Cannot index by location index with a" " non-integer key".format(klass=type(i), kind=str(float)) ) - with catch_warnings(record=True): - with pytest.raises(error, match=msg): - idxr(s)[3.0] + with pytest.raises(error, match=msg): + idxr(s)[3.0] # label based can be a TypeError or KeyError if s.index.inferred_type in ["string", "unicode", "mixed"]: @@ -158,10 +148,9 @@ def test_scalar_non_numeric(self): s2.loc[3.0] = 10 assert s2.index.is_object() - for idxr in [lambda x: x.ix, lambda x: x]: + for idxr in [lambda x: x]: s2 = s.copy() - with catch_warnings(record=True): - idxr(s2)[3.0] = 0 + idxr(s2)[3.0] = 0 assert s2.index.is_object() # fallsback to position selection, series only @@ -175,7 +164,6 @@ def test_scalar_non_numeric(self): with pytest.raises(TypeError, match=msg): s[3.0] - @ignore_ix def test_scalar_with_mixed(self): s2 = Series([1, 2, 3], index=["a", "b", "c"]) @@ -183,7 +171,7 @@ def test_scalar_with_mixed(self): # lookup in a pure stringstr # with an invalid indexer - for idxr in [lambda x: x.ix, lambda x: x, lambda x: x.iloc]: + for idxr in [lambda x: x, lambda x: x.iloc]: msg = ( r"cannot do label indexing" @@ -193,9 +181,8 @@ def test_scalar_with_mixed(self): klass=str(Index), kind=str(float) ) ) - with catch_warnings(record=True): - with pytest.raises(TypeError, match=msg): - idxr(s2)[1.0] + with pytest.raises(TypeError, match=msg): + idxr(s2)[1.0] with pytest.raises(KeyError, match=r"^1$"): s2.loc[1.0] @@ -220,23 +207,6 @@ def test_scalar_with_mixed(self): expected = 2 assert result == expected - # mixed index so we have label - # indexing - for idxr in [lambda x: x.ix]: - with catch_warnings(record=True): - - msg = ( - r"cannot do label indexing" - r" on {klass} with these indexers \[1\.0\] of" - r" {kind}".format(klass=str(Index), kind=str(float)) - ) - with pytest.raises(TypeError, match=msg): - idxr(s3)[1.0] - - result = idxr(s3)[1] - expected = 2 - assert result == expected - msg = "Cannot index by location index with a non-integer key" with pytest.raises(TypeError, match=msg): s3.iloc[1.0] @@ -247,7 +217,6 @@ def test_scalar_with_mixed(self): expected = 3 assert result == expected - @ignore_ix def test_scalar_integer(self): # test how scalar float indexers work on int indexes @@ -261,22 +230,13 @@ def test_scalar_integer(self): ]: # coerce to equal int - for idxr, getitem in [ - (lambda x: x.ix, False), - (lambda x: x.loc, False), - (lambda x: x, True), - ]: + for idxr, getitem in [(lambda x: x.loc, False), (lambda x: x, True)]: - with catch_warnings(record=True): - result = idxr(s)[3.0] + result = idxr(s)[3.0] self.check(result, s, 3, getitem) # coerce to equal int - for idxr, getitem in [ - (lambda x: x.ix, False), - (lambda x: x.loc, False), - (lambda x: x, True), - ]: + for idxr, getitem in [(lambda x: x.loc, False), (lambda x: x, True)]: if isinstance(s, Series): @@ -292,20 +252,18 @@ def compare(x, y): expected = Series(100.0, index=range(len(s)), name=3) s2 = s.copy() - with catch_warnings(record=True): - idxr(s2)[3.0] = 100 + idxr(s2)[3.0] = 100 - result = idxr(s2)[3.0] - compare(result, expected) + result = idxr(s2)[3.0] + compare(result, expected) - result = idxr(s2)[3] - compare(result, expected) + result = idxr(s2)[3] + compare(result, expected) # contains # coerce to equal int assert 3.0 in s - @ignore_ix def test_scalar_float(self): # scalar float indexers work on a float index @@ -319,11 +277,7 @@ def test_scalar_float(self): # assert all operations except for iloc are ok indexer = index[3] - for idxr, getitem in [ - (lambda x: x.ix, False), - (lambda x: x.loc, False), - (lambda x: x, True), - ]: + for idxr, getitem in [(lambda x: x.loc, False), (lambda x: x, True)]: # getting result = idxr(s)[indexer] @@ -332,14 +286,12 @@ def test_scalar_float(self): # setting s2 = s.copy() - with catch_warnings(record=True): - result = idxr(s2)[indexer] + result = idxr(s2)[indexer] self.check(result, s, 3, getitem) # random integer is a KeyError - with catch_warnings(record=True): - with pytest.raises(KeyError, match=r"^3\.5$"): - idxr(s)[3.5] + with pytest.raises(KeyError, match=r"^3\.5$"): + idxr(s)[3.5] # contains assert 3.0 in s @@ -365,7 +317,6 @@ def test_scalar_float(self): with pytest.raises(TypeError, match=msg): s2.iloc[3.0] = 0 - @ignore_ix def test_slice_non_numeric(self): # GH 4892 @@ -397,12 +348,7 @@ def test_slice_non_numeric(self): with pytest.raises(TypeError, match=msg): s.iloc[l] - for idxr in [ - lambda x: x.ix, - lambda x: x.loc, - lambda x: x.iloc, - lambda x: x, - ]: + for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]: msg = ( "cannot do slice indexing" @@ -414,9 +360,8 @@ def test_slice_non_numeric(self): kind_int=str(int), ) ) - with catch_warnings(record=True): - with pytest.raises(TypeError, match=msg): - idxr(s)[l] + with pytest.raises(TypeError, match=msg): + idxr(s)[l] # setitem for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: @@ -429,12 +374,7 @@ def test_slice_non_numeric(self): with pytest.raises(TypeError, match=msg): s.iloc[l] = 0 - for idxr in [ - lambda x: x.ix, - lambda x: x.loc, - lambda x: x.iloc, - lambda x: x, - ]: + for idxr in [lambda x: x.loc, lambda x: x.iloc, lambda x: x]: msg = ( "cannot do slice indexing" r" on {klass} with these indexers" @@ -445,11 +385,9 @@ def test_slice_non_numeric(self): kind_int=str(int), ) ) - with catch_warnings(record=True): - with pytest.raises(TypeError, match=msg): - idxr(s)[l] = 0 + with pytest.raises(TypeError, match=msg): + idxr(s)[l] = 0 - @ignore_ix def test_slice_integer(self): # same as above, but for Integer based indexes @@ -468,10 +406,9 @@ def test_slice_integer(self): # getitem for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: - for idxr in [lambda x: x.loc, lambda x: x.ix]: + for idxr in [lambda x: x.loc]: - with catch_warnings(record=True): - result = idxr(s)[l] + result = idxr(s)[l] # these are all label indexing # except getitem which is positional @@ -494,9 +431,8 @@ def test_slice_integer(self): # getitem out-of-bounds for l in [slice(-6, 6), slice(-6.0, 6.0)]: - for idxr in [lambda x: x.loc, lambda x: x.ix]: - with catch_warnings(record=True): - result = idxr(s)[l] + for idxr in [lambda x: x.loc]: + result = idxr(s)[l] # these are all label indexing # except getitem which is positional @@ -523,10 +459,9 @@ def test_slice_integer(self): (slice(2.5, 3.5), slice(3, 4)), ]: - for idxr in [lambda x: x.loc, lambda x: x.ix]: + for idxr in [lambda x: x.loc]: - with catch_warnings(record=True): - result = idxr(s)[l] + result = idxr(s)[l] if oob: res = slice(0, 0) else: @@ -546,11 +481,10 @@ def test_slice_integer(self): # setitem for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: - for idxr in [lambda x: x.loc, lambda x: x.ix]: + for idxr in [lambda x: x.loc]: sc = s.copy() - with catch_warnings(record=True): - idxr(sc)[l] = 0 - result = idxr(sc)[l].values.ravel() + idxr(sc)[l] = 0 + result = idxr(sc)[l].values.ravel() assert (result == 0).all() # positional indexing @@ -585,7 +519,6 @@ def test_integer_positional_indexing(self): with pytest.raises(TypeError, match=msg): idxr(s)[l] - @ignore_ix def test_slice_integer_frame_getitem(self): # similar to above, but on the getitem dim (of a DataFrame) @@ -663,10 +596,7 @@ def f(idxr): s[l] = 0 f(lambda x: x.loc) - with catch_warnings(record=True): - f(lambda x: x.ix) - @ignore_ix def test_slice_float(self): # same as above, but for floats @@ -679,20 +609,18 @@ def test_slice_float(self): for l in [slice(3.0, 4), slice(3, 4.0), slice(3.0, 4.0)]: expected = s.iloc[3:4] - for idxr in [lambda x: x.ix, lambda x: x.loc, lambda x: x]: + for idxr in [lambda x: x.loc, lambda x: x]: # getitem - with catch_warnings(record=True): - result = idxr(s)[l] + result = idxr(s)[l] if isinstance(s, Series): tm.assert_series_equal(result, expected) else: tm.assert_frame_equal(result, expected) # setitem s2 = s.copy() - with catch_warnings(record=True): - idxr(s2)[l] = 0 - result = idxr(s2)[l].values.ravel() + idxr(s2)[l] = 0 + result = idxr(s2)[l].values.ravel() assert (result == 0).all() def test_floating_index_doc_example(self):