diff --git a/doc/source/whatsnew/v1.0.0.rst b/doc/source/whatsnew/v1.0.0.rst index 751db2b88069d..13a043a4f89b6 100644 --- a/doc/source/whatsnew/v1.0.0.rst +++ b/doc/source/whatsnew/v1.0.0.rst @@ -151,6 +151,8 @@ Other API changes - :meth:`pandas.api.types.infer_dtype` will now return "integer-na" for integer and ``np.nan`` mix (:issue:`27283`) - :meth:`MultiIndex.from_arrays` will no longer infer names from arrays if ``names=None`` is explicitly provided (:issue:`27292`) +- In order to improve tab-completion, Pandas does not include most deprecated attributes when introspecting a pandas object using ``dir`` (e.g. ``dir(df)``). + To see which attributes are excluded, see an object's ``_deprecations`` attribute, for example ``pd.DataFrame._deprecations`` (:issue:`28805`). - The returned dtype of ::func:`pd.unique` now matches the input dtype. (:issue:`27874`) - diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index bab1127e6e539..2ebfd36eb673f 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -331,7 +331,7 @@ class Categorical(ExtensionArray, PandasObject): __array_priority__ = 1000 _dtype = CategoricalDtype(ordered=False) # tolist is not actually deprecated, just suppressed in the __dir__ - _deprecations = frozenset(["labels", "tolist"]) + _deprecations = PandasObject._deprecations | frozenset(["tolist", "get_values"]) _typ = "categorical" def __init__( @@ -2522,6 +2522,10 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin): >>> s.cat.as_unordered() """ + _deprecations = PandasObject._deprecations | frozenset( + ["categorical", "index", "name"] + ) + def __init__(self, data): self._validate(data) self._parent = data.values diff --git a/pandas/core/arrays/sparse/array.py b/pandas/core/arrays/sparse/array.py index 5acc922734529..e1691de234335 100644 --- a/pandas/core/arrays/sparse/array.py +++ b/pandas/core/arrays/sparse/array.py @@ -263,6 +263,7 @@ class SparseArray(PandasObject, ExtensionArray, ExtensionOpsMixin): _pandas_ftype = "sparse" _subtyp = "sparse_array" # register ABCSparseArray + _deprecations = PandasObject._deprecations | frozenset(["get_values"]) def __init__( self, diff --git a/pandas/core/base.py b/pandas/core/base.py index 4d5b20c56df5a..e54d07096a3d0 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -648,6 +648,7 @@ class IndexOpsMixin: # ndarray compatibility __array_priority__ = 1000 + _deprecations = frozenset(["item"]) def transpose(self, *args, **kwargs): """ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index a135f567fe6f4..447ebcd5c56b1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -170,7 +170,19 @@ class NDFrame(PandasObject, SelectionMixin): _internal_names_set = set(_internal_names) # type: Set[str] _accessors = set() # type: Set[str] _deprecations = frozenset( - ["as_blocks", "blocks", "is_copy", "ftypes", "ix"] + [ + "as_blocks", + "as_matrix", + "blocks", + "clip_lower", + "clip_upper", + "get_dtype_counts", + "get_ftype_counts", + "get_values", + "is_copy", + "ftypes", + "ix", + ] ) # type: FrozenSet[str] _metadata = [] # type: List[str] _is_copy = None diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 86692ed602651..c9c02ad9e496a 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -205,8 +205,10 @@ class Index(IndexOpsMixin, PandasObject): """ # tolist is not actually deprecated, just suppressed in the __dir__ - _deprecations = DirNamesMixin._deprecations | frozenset( - ["tolist", "dtype_str", "get_values", "set_value"] + _deprecations = ( + IndexOpsMixin._deprecations + | DirNamesMixin._deprecations + | frozenset(["tolist", "contains", "dtype_str", "get_values", "set_value"]) ) # To hand over control to subclasses diff --git a/pandas/core/indexes/multi.py b/pandas/core/indexes/multi.py index 2da74012de968..62599dcb28724 100644 --- a/pandas/core/indexes/multi.py +++ b/pandas/core/indexes/multi.py @@ -229,6 +229,10 @@ class MultiIndex(Index): of the mentioned helper methods. """ + _deprecations = Index._deprecations | frozenset( + ["labels", "set_labels", "to_hierarchical"] + ) + # initialize to zero-length tuples to make everything work _typ = "multiindex" _names = FrozenList() diff --git a/pandas/core/series.py b/pandas/core/series.py index 97e8a2dbac7f5..4933e0915686f 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -175,11 +175,24 @@ class Series(base.IndexOpsMixin, generic.NDFrame): _metadata = ["name"] _accessors = {"dt", "cat", "str", "sparse"} - # tolist is not actually deprecated, just suppressed in the __dir__ _deprecations = ( - generic.NDFrame._deprecations + base.IndexOpsMixin._deprecations + | generic.NDFrame._deprecations | DirNamesMixin._deprecations - | frozenset(["asobject", "reshape", "valid", "tolist", "ftype", "real", "imag"]) + | frozenset( + [ + "tolist", # tolist is not deprecated, just suppressed in the __dir__ + "asobject", + "compress", + "valid", + "ftype", + "real", + "imag", + "put", + "ptp", + "nonzero", + ] + ) ) # Override cache_readonly bc Series is mutable diff --git a/pandas/tests/series/test_api.py b/pandas/tests/series/test_api.py index 762f4a37d17cc..998f8b6f7d8a4 100644 --- a/pandas/tests/series/test_api.py +++ b/pandas/tests/series/test_api.py @@ -247,9 +247,6 @@ def test_tab_completion(self): def test_tab_completion_with_categorical(self): # test the tab completion display ok_for_cat = [ - "name", - "index", - "categorical", "categories", "codes", "ordered",