Skip to content

Commit 66f4cc1

Browse files
jrebackTomAugspurger
authored andcommitted
BUG: remove tab completion for deprecated functions (#17683)
closes #17674
1 parent b5842bb commit 66f4cc1

File tree

7 files changed

+30
-8
lines changed

7 files changed

+30
-8
lines changed

pandas/core/accessor.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
class DirNamesMixin(object):
1212
_accessors = frozenset([])
13+
_deprecations = frozenset([])
1314

1415
def _dir_deletions(self):
1516
""" delete unwanted __dir__ for this object """
16-
return self._accessors
17+
return self._accessors | self._deprecations
1718

1819
def _dir_additions(self):
1920
""" add addtional __dir__ for this object """

pandas/core/categorical.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ class Categorical(PandasObject):
231231
# ops, which raise
232232
__array_priority__ = 1000
233233
_dtype = CategoricalDtype()
234+
_deprecations = frozenset(['labels'])
234235
_typ = 'categorical'
235236

236237
def __init__(self, values, categories=None, ordered=None, dtype=None,
@@ -412,13 +413,6 @@ def dtype(self):
412413
"""The :ref:`~pandas.api.types.CategoricalDtype` for this instance"""
413414
return self._dtype
414415

415-
def __dir__(self):
416-
# Avoid IPython warnings for deprecated properties
417-
# https://github.com/pandas-dev/pandas/issues/16409
418-
rv = set(dir(type(self)))
419-
rv.discard("labels")
420-
return sorted(rv)
421-
422416
@property
423417
def _constructor(self):
424418
return Categorical

pandas/core/frame.py

+1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def _constructor(self):
299299
return DataFrame
300300

301301
_constructor_sliced = Series
302+
_deprecations = NDFrame._deprecations | frozenset(['sortlevel'])
302303

303304
@property
304305
def _constructor_expanddim(self):

pandas/core/generic.py

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class NDFrame(PandasObject, SelectionMixin):
112112
'__array_interface__']
113113
_internal_names_set = set(_internal_names)
114114
_accessors = frozenset([])
115+
_deprecations = frozenset(['as_blocks', 'blocks',
116+
'consolidate', 'convert_objects'])
115117
_metadata = []
116118
is_copy = None
117119

pandas/core/series.py

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
145145
"""
146146
_metadata = ['name']
147147
_accessors = frozenset(['dt', 'cat', 'str'])
148+
_deprecations = generic.NDFrame._deprecations | frozenset(
149+
['sortlevel', 'reshape'])
148150
_allow_index_ops = True
149151

150152
def __init__(self, data=None, index=None, dtype=None, name=None,

pandas/tests/frame/test_api.py

+11
Original file line numberDiff line numberDiff line change
@@ -438,3 +438,14 @@ def _check_f(base, f):
438438
# rename
439439
f = lambda x: x.rename({1: 'foo'}, inplace=True)
440440
_check_f(d.copy(), f)
441+
442+
def test_tab_complete_warning(self, ip):
443+
# https://github.com/pandas-dev/pandas/issues/16409
444+
pytest.importorskip('IPython', minversion="6.0.0")
445+
from IPython.core.completer import provisionalcompleter
446+
447+
code = "import pandas as pd; df = pd.DataFrame()"
448+
ip.run_code(code)
449+
with tm.assert_produces_warning(None):
450+
with provisionalcompleter('ignore'):
451+
list(ip.Completer.completions('df.', 1))

pandas/tests/series/test_api.py

+11
Original file line numberDiff line numberDiff line change
@@ -407,3 +407,14 @@ def test_empty_method(self):
407407

408408
for full_series in [pd.Series([1]), pd.Series(index=[1])]:
409409
assert not full_series.empty
410+
411+
def test_tab_complete_warning(self, ip):
412+
# https://github.com/pandas-dev/pandas/issues/16409
413+
pytest.importorskip('IPython', minversion="6.0.0")
414+
from IPython.core.completer import provisionalcompleter
415+
416+
code = "import pandas as pd; s = pd.Series()"
417+
ip.run_code(code)
418+
with tm.assert_produces_warning(None):
419+
with provisionalcompleter('ignore'):
420+
list(ip.Completer.completions('s.', 1))

0 commit comments

Comments
 (0)