Skip to content

Commit da2d290

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

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

doc/source/whatsnew/v0.20.2.txt

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ Bug Fixes
3838

3939
- Bug in using ``pathlib.Path`` or ``py.path.local`` objects with io functions (:issue:`16291`)
4040

41+
42+
- Fixed a compatibility issue with IPython 6.0's tab completion showing deprecation warnings on Categoricals (:issue:`16409`)
43+
44+
4145
Conversion
4246
^^^^^^^^^^
4347

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)