From 3c30184779863ba031fc90c885891261ddc312e4 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 17 May 2019 08:25:48 +0200 Subject: [PATCH 1/2] DEPR: Change .ix DeprecationWarning -> FutureWarning --- pandas/core/indexing.py | 2 +- pandas/tests/frame/test_indexing.py | 156 +++++++++--------- pandas/tests/indexing/common.py | 2 +- pandas/tests/indexing/multiindex/test_ix.py | 4 +- pandas/tests/indexing/multiindex/test_loc.py | 4 +- .../tests/indexing/multiindex/test_partial.py | 4 +- .../tests/indexing/multiindex/test_setitem.py | 4 +- .../tests/indexing/multiindex/test_slice.py | 2 +- pandas/tests/indexing/test_callable.py | 6 +- .../indexing/test_chaining_and_caching.py | 2 +- pandas/tests/indexing/test_floats.py | 2 +- pandas/tests/indexing/test_iloc.py | 18 +- pandas/tests/indexing/test_ix.py | 6 +- pandas/tests/indexing/test_loc.py | 2 +- pandas/tests/indexing/test_partial.py | 2 +- pandas/tests/series/indexing/test_indexing.py | 2 +- pandas/tests/test_multilevel.py | 6 +- 17 files changed, 112 insertions(+), 112 deletions(-) diff --git a/pandas/core/indexing.py b/pandas/core/indexing.py index 65123a8f0f5a7..d243d74b9b745 100755 --- a/pandas/core/indexing.py +++ b/pandas/core/indexing.py @@ -1419,7 +1419,7 @@ class _IXIndexer(_NDFrameIndexer): def __init__(self, name, obj): warnings.warn(self._ix_deprecation_warning, - DeprecationWarning, stacklevel=2) + FutureWarning, stacklevel=2) super().__init__(name, obj) @Appender(_NDFrameIndexer._validate_key.__doc__) diff --git a/pandas/tests/frame/test_indexing.py b/pandas/tests/frame/test_indexing.py index 104886bb3e446..adb8c97584463 100644 --- a/pandas/tests/frame/test_indexing.py +++ b/pandas/tests/frame/test_indexing.py @@ -361,7 +361,7 @@ def test_getitem_ix_mixed_integer(self): assert_frame_equal(result, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[[1, 10]] expected = df.ix[Index([1, 10], dtype=object)] assert_frame_equal(result, expected) @@ -381,34 +381,34 @@ def test_getitem_ix_mixed_integer(self): def test_getitem_setitem_ix_negative_integers(self): with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = self.frame.ix[:, -1] assert_series_equal(result, self.frame['D']) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = self.frame.ix[:, [-1]] assert_frame_equal(result, self.frame[['D']]) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = self.frame.ix[:, [-1, -2]] assert_frame_equal(result, self.frame[['D', 'C']]) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) self.frame.ix[:, [-1]] = 0 assert (self.frame['D'] == 0).all() df = DataFrame(np.random.randn(8, 4)) # ix does label-based indexing when having an integer index with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) with pytest.raises(KeyError): df.ix[[-1]] with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) with pytest.raises(KeyError): df.ix[:, [-1]] @@ -416,11 +416,11 @@ def test_getitem_setitem_ix_negative_integers(self): a = DataFrame(np.random.randn(20, 2), index=[chr(x + 65) for x in range(20)]) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) a.ix[-1] = a.ix[-2] with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + 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' @@ -798,19 +798,19 @@ def test_getitem_fancy_2d(self): f = self.frame with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_frame_equal(f.ix[:, ['B', 'A']], f.reindex(columns=['B', 'A'])) subidx = self.frame.index[[5, 4, 1]] with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_frame_equal(f.ix[subidx, ['B', 'A']], f.reindex(index=subidx, columns=['B', 'A'])) # slicing rows, etc. with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_frame_equal(f.ix[5:10], f[5:10]) assert_frame_equal(f.ix[5:10, :], f[5:10]) assert_frame_equal(f.ix[:5, ['A', 'B']], @@ -819,26 +819,26 @@ def test_getitem_fancy_2d(self): # slice rows with labels, inclusive! with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) expected = f.ix[5:11] result = f.ix[f.index[5]:f.index[10]] assert_frame_equal(expected, result) # slice columns with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_frame_equal(f.ix[:, :2], f.reindex(columns=['A', 'B'])) # get view with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) exp = f.copy() f.ix[5:10].values[:] = 5 exp.values[5:10] = 5 assert_frame_equal(f, exp) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) msg = "Cannot index with multidimensional key" with pytest.raises(ValueError, match=msg): f.ix[f > 0.5] @@ -898,7 +898,7 @@ def test_setitem_fancy_2d(self): expected = frame.copy() with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame.ix[:, ['B', 'A']] = 1 expected['B'] = 1. expected['A'] = 1. @@ -914,7 +914,7 @@ def test_setitem_fancy_2d(self): values = np.random.randn(3, 2) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame.ix[subidx, ['B', 'A']] = values frame2.ix[[5, 4, 1], ['B', 'A']] = values @@ -928,14 +928,14 @@ def test_setitem_fancy_2d(self): frame = self.frame.copy() with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) expected1 = self.frame.copy() frame.ix[5:10] = 1. expected1.values[5:10] = 1. assert_frame_equal(frame, expected1) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) expected2 = self.frame.copy() arr = np.random.randn(5, len(frame.columns)) frame.ix[5:10] = arr @@ -944,7 +944,7 @@ def test_setitem_fancy_2d(self): # case 4 with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame = self.frame.copy() frame.ix[5:10, :] = 1. assert_frame_equal(frame, expected1) @@ -953,7 +953,7 @@ def test_setitem_fancy_2d(self): # case 5 with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame = self.frame.copy() frame2 = self.frame.copy() @@ -966,13 +966,13 @@ def test_setitem_fancy_2d(self): assert_frame_equal(frame, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame2.ix[:5, [0, 1]] = values assert_frame_equal(frame2, expected) # case 6: slice rows with labels, inclusive! with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame = self.frame.copy() expected = self.frame.copy() @@ -982,7 +982,7 @@ def test_setitem_fancy_2d(self): # case 7: slice columns with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame = self.frame.copy() frame2 = self.frame.copy() expected = self.frame.copy() @@ -1025,7 +1025,7 @@ def test_fancy_setitem_int_labels(self): df = DataFrame(np.random.randn(10, 5), index=np.arange(0, 20, 2)) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) tmp = df.copy() exp = df.copy() tmp.ix[[0, 2, 4]] = 5 @@ -1033,7 +1033,7 @@ def test_fancy_setitem_int_labels(self): assert_frame_equal(tmp, exp) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) tmp = df.copy() exp = df.copy() tmp.ix[6] = 5 @@ -1041,7 +1041,7 @@ def test_fancy_setitem_int_labels(self): assert_frame_equal(tmp, exp) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) tmp = df.copy() exp = df.copy() tmp.ix[:, 2] = 5 @@ -1055,25 +1055,25 @@ def test_fancy_getitem_int_labels(self): df = DataFrame(np.random.randn(10, 5), index=np.arange(0, 20, 2)) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[[4, 2, 0], [2, 0]] expected = df.reindex(index=[4, 2, 0], columns=[2, 0]) assert_frame_equal(result, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[[4, 2, 0]] expected = df.reindex(index=[4, 2, 0]) assert_frame_equal(result, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[4] expected = df.xs(4) assert_series_equal(result, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[:, 3] expected = df[3] assert_series_equal(result, expected) @@ -1082,7 +1082,7 @@ def test_fancy_index_int_labels_exceptions(self): df = DataFrame(np.random.randn(10, 5), index=np.arange(0, 20, 2)) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) # labels that aren't contained with pytest.raises(KeyError, match=r"\[1\] not in index"): @@ -1105,7 +1105,7 @@ def test_fancy_index_int_labels_exceptions(self): def test_setitem_fancy_mixed_2d(self): with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) self.mixed_frame.ix[:5, ['C', 'B', 'A']] = 5 result = self.mixed_frame.ix[:5, ['C', 'B', 'A']] assert (result.values == 5).all() @@ -1119,7 +1119,7 @@ def test_setitem_fancy_mixed_2d(self): # #1432 with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) df = DataFrame({1: [1., 2., 3.], 2: [3, 4, 5]}) assert df._is_mixed_type @@ -1137,32 +1137,32 @@ def test_ix_align(self): df = df_orig.copy() with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) df.ix[:, 0] = b assert_series_equal(df.ix[:, 0].reindex(b.index), b) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) dft = df_orig.T dft.ix[0, :] = b assert_series_equal(dft.ix[0, :].reindex(b.index), b) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) df = df_orig.copy() df.ix[:5, 0] = b s = df.ix[:5, 0] assert_series_equal(s, b.reindex(s.index)) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) dft = df_orig.T dft.ix[0, :5] = b s = dft.ix[0, :5] assert_series_equal(s, b.reindex(s.index)) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) df = df_orig.copy() idx = [0, 1, 3, 5] df.ix[idx, 0] = b @@ -1170,7 +1170,7 @@ def test_ix_align(self): assert_series_equal(s, b.reindex(s.index)) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) dft = df_orig.T dft.ix[0, idx] = b s = dft.ix[0, idx] @@ -1182,7 +1182,7 @@ def test_ix_frame_align(self): df = df_orig.copy() with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) df.ix[:3] = b out = b.ix[:3] assert_frame_equal(out, b) @@ -1190,14 +1190,14 @@ def test_ix_frame_align(self): b.sort_index(inplace=True) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) df = df_orig.copy() df.ix[[0, 1, 2]] = b out = df.ix[[0, 1, 2]].reindex(b.index) assert_frame_equal(out, b) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) df = df_orig.copy() df.ix[:3] = b out = df.ix[:3] @@ -1240,7 +1240,7 @@ def test_ix_multi_take_nonint_index(self): df = DataFrame(np.random.randn(3, 2), index=['x', 'y', 'z'], columns=['a', 'b']) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) rs = df.ix[[0], [0]] xp = df.reindex(['x'], columns=['a']) assert_frame_equal(rs, xp) @@ -1249,7 +1249,7 @@ def test_ix_multi_take_multiindex(self): df = DataFrame(np.random.randn(3, 2), index=['x', 'y', 'z'], columns=[['a', 'b'], ['1', '2']]) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) rs = df.ix[[0], [0]] xp = df.reindex(['x'], columns=[('a', '1')]) assert_frame_equal(rs, xp) @@ -1259,17 +1259,17 @@ def test_ix_dup(self): df = DataFrame(np.random.randn(len(idx), 3), idx) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) sub = df.ix[:'d'] assert_frame_equal(sub, df) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) sub = df.ix['a':'c'] assert_frame_equal(sub, df.ix[0:4]) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) sub = df.ix['b':'d'] assert_frame_equal(sub, df.ix[2:]) @@ -1278,57 +1278,57 @@ def test_getitem_fancy_1d(self): # return self if no slicing...for now with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert f.ix[:, :] is f # low dimensional slice with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) xs1 = f.ix[2, ['C', 'B', 'A']] xs2 = f.xs(f.index[2]).reindex(['C', 'B', 'A']) tm.assert_series_equal(xs1, xs2) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) ts1 = f.ix[5:10, 2] ts2 = f[f.columns[2]][5:10] tm.assert_series_equal(ts1, ts2) # positional xs with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) xs1 = f.ix[0] xs2 = f.xs(f.index[0]) tm.assert_series_equal(xs1, xs2) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) xs1 = f.ix[f.index[5]] xs2 = f.xs(f.index[5]) tm.assert_series_equal(xs1, xs2) # single column with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_series_equal(f.ix[:, 'A'], f['A']) # return view with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) exp = f.copy() exp.values[5] = 4 f.ix[5][:] = 4 tm.assert_frame_equal(exp, f) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) exp.values[:, 1] = 6 f.ix[:, 1][:] = 6 tm.assert_frame_equal(exp, f) # slice of mixed-frame with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) xs = self.mixed_frame.ix[5] exp = self.mixed_frame.xs(self.mixed_frame.index[5]) tm.assert_series_equal(xs, exp) @@ -1340,7 +1340,7 @@ def test_setitem_fancy_1d(self): expected = self.frame.copy() with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame.ix[2, ['C', 'B', 'A']] = [1., 2., 3.] expected['C'][2] = 1. expected['B'][2] = 2. @@ -1348,7 +1348,7 @@ def test_setitem_fancy_1d(self): assert_frame_equal(frame, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame2 = self.frame.copy() frame2.ix[2, [3, 2, 1]] = [1., 2., 3.] assert_frame_equal(frame, expected) @@ -1358,14 +1358,14 @@ def test_setitem_fancy_1d(self): expected = self.frame.copy() with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) vals = np.random.randn(5) expected.values[5:10, 2] = vals frame.ix[5:10, 2] = vals assert_frame_equal(frame, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame2 = self.frame.copy() frame2.ix[5:10, 'B'] = vals assert_frame_equal(frame, expected) @@ -1375,13 +1375,13 @@ def test_setitem_fancy_1d(self): expected = self.frame.copy() with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame.ix[4] = 5. expected.values[4] = 5. assert_frame_equal(frame, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame.ix[frame.index[4]] = 6. expected.values[4] = 6. assert_frame_equal(frame, expected) @@ -1391,7 +1391,7 @@ def test_setitem_fancy_1d(self): expected = self.frame.copy() with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) frame.ix[:, 'A'] = 7. expected['A'] = 7. assert_frame_equal(frame, expected) @@ -1912,7 +1912,7 @@ def test_single_element_ix_dont_upcast(self): assert issubclass(self.frame['E'].dtype.type, (int, np.integer)) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = self.frame.ix[self.frame.index[5], 'E'] assert is_integer(result) @@ -1924,7 +1924,7 @@ def test_single_element_ix_dont_upcast(self): df["b"] = 666 with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[0, "b"] assert is_integer(result) result = df.loc[0, "b"] @@ -1932,7 +1932,7 @@ def test_single_element_ix_dont_upcast(self): expected = Series([666], [0], name='b') with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[[0], "b"] assert_series_equal(result, expected) result = df.loc[[0], "b"] @@ -2004,14 +2004,14 @@ def test_iloc_duplicates(self): result = df.iloc[0] with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result2 = df.ix[0] assert isinstance(result, Series) assert_almost_equal(result.values, df.values[0]) assert_series_equal(result, result2) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.T.iloc[:, 0] result2 = df.T.ix[:, 0] assert isinstance(result, Series) @@ -2024,19 +2024,19 @@ def test_iloc_duplicates(self): index=[['i', 'i', 'j'], ['X', 'X', 'Y']]) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) rs = df.iloc[0] xp = df.ix[0] assert_series_equal(rs, xp) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) rs = df.iloc[:, 0] xp = df.T.ix[0] assert_series_equal(rs, xp) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) rs = df.iloc[:, [0]] xp = df.ix[:, [0]] assert_frame_equal(rs, xp) @@ -2263,7 +2263,7 @@ def test_getitem_ix_float_duplicates(self): expect = df.iloc[1:] assert_frame_equal(df.loc[0.2], expect) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_frame_equal(df.ix[0.2], expect) expect = df.iloc[1:, 0] @@ -2273,7 +2273,7 @@ def test_getitem_ix_float_duplicates(self): expect = df.iloc[1:] assert_frame_equal(df.loc[0.2], expect) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_frame_equal(df.ix[0.2], expect) expect = df.iloc[1:, 0] @@ -2284,7 +2284,7 @@ def test_getitem_ix_float_duplicates(self): expect = df.iloc[1:-1] assert_frame_equal(df.loc[0.2], expect) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_frame_equal(df.ix[0.2], expect) expect = df.iloc[1:-1, 0] @@ -2294,7 +2294,7 @@ def test_getitem_ix_float_duplicates(self): expect = df.iloc[[1, -1]] assert_frame_equal(df.loc[0.2], expect) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) assert_frame_equal(df.ix[0.2], expect) expect = df.iloc[[1, -1], 0] @@ -2525,7 +2525,7 @@ def test_index_namedtuple(self): df = DataFrame([(1, 2), (3, 4)], index=index, columns=["A", "B"]) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[IndexType("foo", "bar")]["A"] assert result == 1 diff --git a/pandas/tests/indexing/common.py b/pandas/tests/indexing/common.py index 291d06f5862bf..cefff461ecb68 100644 --- a/pandas/tests/indexing/common.py +++ b/pandas/tests/indexing/common.py @@ -141,7 +141,7 @@ def get_value(self, f, i, values=False): # v = v.__getitem__(a) # return v with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) return f.ix[i] def check_values(self, f, func, values=False): diff --git a/pandas/tests/indexing/multiindex/test_ix.py b/pandas/tests/indexing/multiindex/test_ix.py index 051803b3c55e5..6b6e1dbd859a2 100644 --- a/pandas/tests/indexing/multiindex/test_ix.py +++ b/pandas/tests/indexing/multiindex/test_ix.py @@ -8,7 +8,7 @@ from pandas.util import testing as tm -@pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") class TestMultiIndexIx: def test_frame_setitem_ix(self, multiindex_dataframe_random_data): @@ -23,7 +23,7 @@ def test_frame_setitem_ix(self, multiindex_dataframe_random_data): assert df.loc[('bar', 'two'), 1] == 7 with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) df = frame.copy() df.columns = list(range(3)) df.ix[('bar', 'two'), 1] = 7 diff --git a/pandas/tests/indexing/multiindex/test_loc.py b/pandas/tests/indexing/multiindex/test_loc.py index 3e0867f414bb7..97ef78ff5ce1b 100644 --- a/pandas/tests/indexing/multiindex/test_loc.py +++ b/pandas/tests/indexing/multiindex/test_loc.py @@ -25,7 +25,7 @@ def frame_random_data_integer_multi_index(): return DataFrame(np.random.randn(6, 2), index=index) -@pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") class TestMultiIndexLoc: def test_loc_getitem_series(self): @@ -309,7 +309,7 @@ def test_loc_getitem_duplicates_multiindex_missing_indexers(indexer, is_level1, tm.assert_series_equal(result, expected) -@pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning") +@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)]] diff --git a/pandas/tests/indexing/multiindex/test_partial.py b/pandas/tests/indexing/multiindex/test_partial.py index e52e2a234600a..20830bbe4680b 100644 --- a/pandas/tests/indexing/multiindex/test_partial.py +++ b/pandas/tests/indexing/multiindex/test_partial.py @@ -100,7 +100,7 @@ def test_getitem_partial_column_select(self): tm.assert_frame_equal(result, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[('a', 'y'), [1, 0]] tm.assert_frame_equal(result, expected) @@ -132,7 +132,7 @@ def test_partial_set( # --------------------------------------------------------------------- # AMBIGUOUS CASES! - def test_partial_ix_missing( + def test_partial_loc_missing( self, multiindex_year_month_day_dataframe_random_data): pytest.skip("skipping for now") diff --git a/pandas/tests/indexing/multiindex/test_setitem.py b/pandas/tests/indexing/multiindex/test_setitem.py index 2fbd3a55508a1..44aae4cd55e35 100644 --- a/pandas/tests/indexing/multiindex/test_setitem.py +++ b/pandas/tests/indexing/multiindex/test_setitem.py @@ -11,7 +11,7 @@ from pandas.util import testing as tm -@pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") class TestMultiIndexSetItem: def test_setitem_multiindex(self): @@ -280,7 +280,7 @@ def test_frame_getitem_setitem_multislice(self): tm.assert_series_equal(df['value'], result) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) result = df.ix[:, 'value'] tm.assert_series_equal(df['value'], result) diff --git a/pandas/tests/indexing/multiindex/test_slice.py b/pandas/tests/indexing/multiindex/test_slice.py index 6433a39fe4373..3394c4c06d45a 100644 --- a/pandas/tests/indexing/multiindex/test_slice.py +++ b/pandas/tests/indexing/multiindex/test_slice.py @@ -12,7 +12,7 @@ from pandas.util import testing as tm -@pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") class TestMultiIndexSlicers: def test_per_axis_per_level_getitem(self): diff --git a/pandas/tests/indexing/test_callable.py b/pandas/tests/indexing/test_callable.py index b45f69245cfdc..657309170cac3 100644 --- a/pandas/tests/indexing/test_callable.py +++ b/pandas/tests/indexing/test_callable.py @@ -6,7 +6,7 @@ class TestIndexingCallable: - def test_frame_loc_ix_callable(self): + def test_frame_loc_callable(self): # GH 11485 df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': list('aabb'), 'C': [1, 2, 3, 4]}) @@ -62,7 +62,7 @@ def test_frame_loc_ix_callable(self): res = df.loc[lambda x: 1, lambda x: 'A'] assert res == df.loc[1, 'A'] - def test_frame_loc_ix_callable_mixture(self): + def test_frame_loc_callable_mixture(self): # GH 11485 df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': list('aabb'), 'C': [1, 2, 3, 4]}) @@ -85,7 +85,7 @@ def test_frame_loc_ix_callable_mixture(self): res = df.loc[3, lambda x: ['A', 'B']] tm.assert_series_equal(res, df.loc[3, ['A', 'B']]) - def test_frame_loc_callable(self): + def test_frame_loc_callable_labels(self): # GH 11485 df = pd.DataFrame({'X': [1, 2, 3, 4], 'Y': list('aabb')}, diff --git a/pandas/tests/indexing/test_chaining_and_caching.py b/pandas/tests/indexing/test_chaining_and_caching.py index d4d1f67c600ae..b94d3000a5841 100644 --- a/pandas/tests/indexing/test_chaining_and_caching.py +++ b/pandas/tests/indexing/test_chaining_and_caching.py @@ -355,7 +355,7 @@ def check(result, expected): result4 = df['A'].iloc[2] check(result4, expected) - @pytest.mark.filterwarnings("ignore::DeprecationWarning") + @pytest.mark.filterwarnings("ignore::FutureWarning") def test_cache_updating(self): # GH 4939, make sure to update the cache on setitem diff --git a/pandas/tests/indexing/test_floats.py b/pandas/tests/indexing/test_floats.py index 020fdcfe445de..9a2aae08dbb15 100644 --- a/pandas/tests/indexing/test_floats.py +++ b/pandas/tests/indexing/test_floats.py @@ -8,7 +8,7 @@ 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:DeprecationWarning") +ignore_ix = pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") class TestFloatIndexers: diff --git a/pandas/tests/indexing/test_iloc.py b/pandas/tests/indexing/test_iloc.py index 81c38ee42749c..4fa26dc67ba0c 100644 --- a/pandas/tests/indexing/test_iloc.py +++ b/pandas/tests/indexing/test_iloc.py @@ -383,53 +383,53 @@ def test_iloc_getitem_frame(self): result = df.iloc[2] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) exp = df.ix[4] tm.assert_series_equal(result, exp) result = df.iloc[2, 2] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) exp = df.ix[4, 4] assert result == exp # slice result = df.iloc[4:8] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) expected = df.ix[8:14] tm.assert_frame_equal(result, expected) result = df.iloc[:, 2:3] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) expected = df.ix[:, 4:5] tm.assert_frame_equal(result, expected) # list of integers result = df.iloc[[0, 1, 3]] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) expected = df.ix[[0, 2, 6]] tm.assert_frame_equal(result, expected) result = df.iloc[[0, 1, 3], [0, 1]] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) expected = df.ix[[0, 2, 6], [0, 2]] tm.assert_frame_equal(result, expected) # neg indices result = df.iloc[[-1, 1, 3], [-1, 1]] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) expected = df.ix[[18, 2, 6], [6, 2]] tm.assert_frame_equal(result, expected) # dups indices result = df.iloc[[-1, -1, 1, 3], [-1, 1]] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) expected = df.ix[[18, 18, 2, 6], [6, 2]] tm.assert_frame_equal(result, expected) @@ -437,7 +437,7 @@ def test_iloc_getitem_frame(self): s = Series(index=range(1, 5)) result = df.iloc[s.index] with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) expected = df.ix[[2, 4, 6, 8]] tm.assert_frame_equal(result, expected) diff --git a/pandas/tests/indexing/test_ix.py b/pandas/tests/indexing/test_ix.py index 478032f76e7cb..d56894a8c1f7b 100644 --- a/pandas/tests/indexing/test_ix.py +++ b/pandas/tests/indexing/test_ix.py @@ -16,12 +16,12 @@ def test_ix_deprecation(): # GH 15114 df = DataFrame({'A': [1, 2, 3]}) - with tm.assert_produces_warning(DeprecationWarning, - check_stacklevel=False): + with tm.assert_produces_warning(FutureWarning, + check_stacklevel=True): df.ix[1, 'A'] -@pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning") +@pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") class TestIX: def test_ix_loc_setitem_consistency(self): diff --git a/pandas/tests/indexing/test_loc.py b/pandas/tests/indexing/test_loc.py index b3beec95151fb..8351d5646e816 100644 --- a/pandas/tests/indexing/test_loc.py +++ b/pandas/tests/indexing/test_loc.py @@ -654,7 +654,7 @@ def test_loc_name(self): assert result == 'index_name' with catch_warnings(record=True): - filterwarnings("ignore", "\\n.ix", DeprecationWarning) + filterwarnings("ignore", "\\n.ix", FutureWarning) result = df.ix[[0, 1]].index.name assert result == 'index_name' diff --git a/pandas/tests/indexing/test_partial.py b/pandas/tests/indexing/test_partial.py index c1d530cc890e5..0c53b8c7a0350 100644 --- a/pandas/tests/indexing/test_partial.py +++ b/pandas/tests/indexing/test_partial.py @@ -16,7 +16,7 @@ class TestPartialSetting: - @pytest.mark.filterwarnings("ignore:\\n.ix:DeprecationWarning") + @pytest.mark.filterwarnings("ignore:\\n.ix:FutureWarning") def test_partial_setting(self): # GH2578, allow ix and friends to partially set diff --git a/pandas/tests/series/indexing/test_indexing.py b/pandas/tests/series/indexing/test_indexing.py index b82beda5d554a..6641311faace2 100644 --- a/pandas/tests/series/indexing/test_indexing.py +++ b/pandas/tests/series/indexing/test_indexing.py @@ -574,7 +574,7 @@ def test_slice_can_reorder_not_uniquely_indexed(): s[::-1] # it works! -def test_ix_setitem(test_data): +def test_loc_setitem(test_data): inds = test_data.series.index[[3, 4, 7]] result = test_data.series.copy() diff --git a/pandas/tests/test_multilevel.py b/pandas/tests/test_multilevel.py index 737445b3fb572..e8d6b3bcaa77f 100644 --- a/pandas/tests/test_multilevel.py +++ b/pandas/tests/test_multilevel.py @@ -188,7 +188,7 @@ def test_reindex(self): tm.assert_frame_equal(reindexed, expected) with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) reindexed = self.frame.ix[[('foo', 'one'), ('bar', 'one')]] tm.assert_frame_equal(reindexed, expected) @@ -201,7 +201,7 @@ def test_reindex_preserve_levels(self): assert chunk.index is new_index with catch_warnings(record=True): - simplefilter("ignore", DeprecationWarning) + simplefilter("ignore", FutureWarning) chunk = self.ymd.ix[new_index] assert chunk.index is new_index @@ -1014,7 +1014,7 @@ def test_multilevel_consolidate(self): df['Totals', ''] = df.sum(1) df = df._consolidate() - def test_ix_preserve_names(self): + def test_loc_preserve_names(self): result = self.ymd.loc[2000] result2 = self.ymd['A'].loc[2000] assert result.index.names == self.ymd.index.names[1:] From bb93f63e04091ab861ffdc7d45df3cedd2556354 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 17 May 2019 11:39:05 +0200 Subject: [PATCH 2/2] add whatsnew --- doc/source/whatsnew/v0.25.0.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index d38ee7b8b589a..5f43512b69098 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -255,6 +255,7 @@ Other API Changes Deprecations ~~~~~~~~~~~~ +- The deprecated ``.ix[]`` indexer now raises a more visible FutureWarning instead of DeprecationWarning (:issue:`26438`). - Deprecated the ``units=M`` (months) and ``units=Y`` (year) parameters for ``units`` of :func:`pandas.to_timedelta`, :func:`pandas.Timedelta` and :func:`pandas.TimedeltaIndex` (:issue:`16344`) - The functions :func:`pandas.to_datetime` and :func:`pandas.to_timedelta` have deprecated the ``box`` keyword. Instead, use :meth:`to_numpy` or :meth:`Timestamp.to_datetime64` or :meth:`Timedelta.to_timedelta64`. (:issue:`24416`) - The :meth:`DataFrame.compound` and :meth:`Series.compound` methods are deprecated and will be removed in a future version.