From 3946c83cfb45ea751c29ee091fea9e2b9f042c28 Mon Sep 17 00:00:00 2001 From: Jeff Reback Date: Tue, 26 Sep 2017 09:39:56 -0400 Subject: [PATCH] BUG: remove tab completion for deprecated functions closes #17674 --- pandas/core/accessor.py | 3 ++- pandas/core/categorical.py | 8 +------- pandas/core/frame.py | 1 + pandas/core/generic.py | 2 ++ pandas/core/series.py | 2 ++ pandas/tests/frame/test_api.py | 11 +++++++++++ pandas/tests/series/test_api.py | 11 +++++++++++ 7 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pandas/core/accessor.py b/pandas/core/accessor.py index c8476841bfce4..7a2da9655cc4a 100644 --- a/pandas/core/accessor.py +++ b/pandas/core/accessor.py @@ -10,10 +10,11 @@ class DirNamesMixin(object): _accessors = frozenset([]) + _deprecations = frozenset([]) def _dir_deletions(self): """ delete unwanted __dir__ for this object """ - return self._accessors + return self._accessors | self._deprecations def _dir_additions(self): """ add addtional __dir__ for this object """ diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index 8b055e9ae59c3..011aa74632296 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -231,6 +231,7 @@ class Categorical(PandasObject): # ops, which raise __array_priority__ = 1000 _dtype = CategoricalDtype() + _deprecations = frozenset(['labels']) _typ = 'categorical' def __init__(self, values, categories=None, ordered=None, dtype=None, @@ -412,13 +413,6 @@ def dtype(self): """The :ref:`~pandas.api.types.CategoricalDtype` for this instance""" return self._dtype - def __dir__(self): - # Avoid IPython warnings for deprecated properties - # https://github.com/pandas-dev/pandas/issues/16409 - rv = set(dir(type(self))) - rv.discard("labels") - return sorted(rv) - @property def _constructor(self): return Categorical diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 912dbdb9de705..579d9f10d5875 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -299,6 +299,7 @@ def _constructor(self): return DataFrame _constructor_sliced = Series + _deprecations = NDFrame._deprecations | frozenset(['sortlevel']) @property def _constructor_expanddim(self): diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a7be145f21083..2fb0e348c01c0 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -112,6 +112,8 @@ class NDFrame(PandasObject, SelectionMixin): '__array_interface__'] _internal_names_set = set(_internal_names) _accessors = frozenset([]) + _deprecations = frozenset(['as_blocks', 'blocks', + 'consolidate', 'convert_objects']) _metadata = [] is_copy = None diff --git a/pandas/core/series.py b/pandas/core/series.py index db8ee2529ef57..89add1ef4c590 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -145,6 +145,8 @@ class Series(base.IndexOpsMixin, generic.NDFrame): """ _metadata = ['name'] _accessors = frozenset(['dt', 'cat', 'str']) + _deprecations = generic.NDFrame._deprecations | frozenset( + ['sortlevel', 'reshape']) _allow_index_ops = True def __init__(self, data=None, index=None, dtype=None, name=None, diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 230a5806ccb2e..5ea8230ced41b 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -438,3 +438,14 @@ def _check_f(base, f): # rename f = lambda x: x.rename({1: 'foo'}, inplace=True) _check_f(d.copy(), f) + + def test_tab_complete_warning(self, ip): + # https://github.com/pandas-dev/pandas/issues/16409 + pytest.importorskip('IPython', minversion="6.0.0") + from IPython.core.completer import provisionalcompleter + + code = "import pandas as pd; df = pd.DataFrame()" + ip.run_code(code) + with tm.assert_produces_warning(None): + with provisionalcompleter('ignore'): + list(ip.Completer.completions('df.', 1)) diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index d0805e2bb54d2..56b8a90ec0c9f 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -407,3 +407,14 @@ def test_empty_method(self): for full_series in [pd.Series([1]), pd.Series(index=[1])]: assert not full_series.empty + + def test_tab_complete_warning(self, ip): + # https://github.com/pandas-dev/pandas/issues/16409 + pytest.importorskip('IPython', minversion="6.0.0") + from IPython.core.completer import provisionalcompleter + + code = "import pandas as pd; s = pd.Series()" + ip.run_code(code) + with tm.assert_produces_warning(None): + with provisionalcompleter('ignore'): + list(ip.Completer.completions('s.', 1))