Skip to content

Commit 2d048c9

Browse files
committed
COMPAT: Catch warnings on tab-complete in IPy 6
Properties may run code with Jedi completion in IPython 6 Closes pandas-dev#16409
1 parent 0f55de1 commit 2d048c9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pandas/core/categorical.py

+5
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ def __init__(self, values, categories=None, ordered=False, fastpath=False):
342342
self._categories = categories
343343
self._codes = coerce_indexer_dtype(codes, categories)
344344

345+
def __dir__(self):
346+
# Avoid IPython warnings for deprecated properties
347+
# https://github.com/pandas-dev/pandas/issues/16409
348+
return [x for x in dir(self) if x != 'labels']
349+
345350
@property
346351
def _constructor(self):
347352
return Categorical

pandas/tests/test_categorical.py

+15
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,21 @@ def test_unicode_print(self):
736736

737737
assert _rep(c) == expected
738738

739+
def test_tab_complete_warning(self):
740+
# https://github.com/pandas-dev/pandas/issues/16409
741+
pytest.importorskip('IPython', minversion="6.0.0")
742+
from IPython.core.interactiveshell import InteractiveShell
743+
from IPython.core.completer import provisionalcompleter
744+
745+
ip = InteractiveShell()
746+
code = "import pandas as pd; c = pd.Categorical([])"
747+
ip.run_code(code)
748+
with pytest.warns(None) as record:
749+
with provisionalcompleter('ignore'):
750+
list(ip.Completer.completions('c.', 1))
751+
752+
assert len(record) == 0
753+
739754
def test_periodindex(self):
740755
idx1 = PeriodIndex(['2014-01', '2014-01', '2014-02', '2014-02',
741756
'2014-03', '2014-03'], freq='M')

0 commit comments

Comments
 (0)