Skip to content

API: Add various deprecated attributes to ._deprecated #28805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
-

Expand Down
6 changes: 5 additions & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ class IndexOpsMixin:

# ndarray compatibility
__array_priority__ = 1000
_deprecations = frozenset(["item"])

def transpose(self, *args, **kwargs):
"""
Expand Down
14 changes: 13 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pandas/core/indexes/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 16 additions & 3 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions pandas/tests/series/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down