Skip to content

Commit 1e92886

Browse files
topper-123jreback
authored andcommitted
API: Add various deprecated attributes to ._deprecated (#28805)
1 parent 4ade26b commit 1e92886

File tree

9 files changed

+46
-10
lines changed

9 files changed

+46
-10
lines changed

doc/source/whatsnew/v1.0.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ Other API changes
151151

152152
- :meth:`pandas.api.types.infer_dtype` will now return "integer-na" for integer and ``np.nan`` mix (:issue:`27283`)
153153
- :meth:`MultiIndex.from_arrays` will no longer infer names from arrays if ``names=None`` is explicitly provided (:issue:`27292`)
154+
- In order to improve tab-completion, Pandas does not include most deprecated attributes when introspecting a pandas object using ``dir`` (e.g. ``dir(df)``).
155+
To see which attributes are excluded, see an object's ``_deprecations`` attribute, for example ``pd.DataFrame._deprecations`` (:issue:`28805`).
154156
- The returned dtype of ::func:`pd.unique` now matches the input dtype. (:issue:`27874`)
155157
-
156158

pandas/core/arrays/categorical.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class Categorical(ExtensionArray, PandasObject):
331331
__array_priority__ = 1000
332332
_dtype = CategoricalDtype(ordered=False)
333333
# tolist is not actually deprecated, just suppressed in the __dir__
334-
_deprecations = frozenset(["labels", "tolist"])
334+
_deprecations = PandasObject._deprecations | frozenset(["tolist", "get_values"])
335335
_typ = "categorical"
336336

337337
def __init__(
@@ -2522,6 +2522,10 @@ class CategoricalAccessor(PandasDelegate, PandasObject, NoNewAttributesMixin):
25222522
>>> s.cat.as_unordered()
25232523
"""
25242524

2525+
_deprecations = PandasObject._deprecations | frozenset(
2526+
["categorical", "index", "name"]
2527+
)
2528+
25252529
def __init__(self, data):
25262530
self._validate(data)
25272531
self._parent = data.values

pandas/core/arrays/sparse/array.py

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ class SparseArray(PandasObject, ExtensionArray, ExtensionOpsMixin):
263263

264264
_pandas_ftype = "sparse"
265265
_subtyp = "sparse_array" # register ABCSparseArray
266+
_deprecations = PandasObject._deprecations | frozenset(["get_values"])
266267

267268
def __init__(
268269
self,

pandas/core/base.py

+1
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ class IndexOpsMixin:
653653

654654
# ndarray compatibility
655655
__array_priority__ = 1000
656+
_deprecations = frozenset(["item"])
656657

657658
def transpose(self, *args, **kwargs):
658659
"""

pandas/core/generic.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,19 @@ class NDFrame(PandasObject, SelectionMixin):
170170
_internal_names_set = set(_internal_names) # type: Set[str]
171171
_accessors = set() # type: Set[str]
172172
_deprecations = frozenset(
173-
["as_blocks", "blocks", "is_copy", "ftypes", "ix"]
173+
[
174+
"as_blocks",
175+
"as_matrix",
176+
"blocks",
177+
"clip_lower",
178+
"clip_upper",
179+
"get_dtype_counts",
180+
"get_ftype_counts",
181+
"get_values",
182+
"is_copy",
183+
"ftypes",
184+
"ix",
185+
]
174186
) # type: FrozenSet[str]
175187
_metadata = [] # type: List[str]
176188
_is_copy = None

pandas/core/indexes/base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,10 @@ class Index(IndexOpsMixin, PandasObject):
205205
"""
206206

207207
# tolist is not actually deprecated, just suppressed in the __dir__
208-
_deprecations = DirNamesMixin._deprecations | frozenset(
209-
["tolist", "dtype_str", "get_values", "set_value"]
208+
_deprecations = (
209+
IndexOpsMixin._deprecations
210+
| DirNamesMixin._deprecations
211+
| frozenset(["tolist", "contains", "dtype_str", "get_values", "set_value"])
210212
)
211213

212214
# To hand over control to subclasses

pandas/core/indexes/multi.py

+4
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ class MultiIndex(Index):
229229
of the mentioned helper methods.
230230
"""
231231

232+
_deprecations = Index._deprecations | frozenset(
233+
["labels", "set_labels", "to_hierarchical"]
234+
)
235+
232236
# initialize to zero-length tuples to make everything work
233237
_typ = "multiindex"
234238
_names = FrozenList()

pandas/core/series.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,24 @@ class Series(base.IndexOpsMixin, generic.NDFrame):
175175

176176
_metadata = ["name"]
177177
_accessors = {"dt", "cat", "str", "sparse"}
178-
# tolist is not actually deprecated, just suppressed in the __dir__
179178
_deprecations = (
180-
generic.NDFrame._deprecations
179+
base.IndexOpsMixin._deprecations
180+
| generic.NDFrame._deprecations
181181
| DirNamesMixin._deprecations
182-
| frozenset(["asobject", "reshape", "valid", "tolist", "ftype", "real", "imag"])
182+
| frozenset(
183+
[
184+
"tolist", # tolist is not deprecated, just suppressed in the __dir__
185+
"asobject",
186+
"compress",
187+
"valid",
188+
"ftype",
189+
"real",
190+
"imag",
191+
"put",
192+
"ptp",
193+
"nonzero",
194+
]
195+
)
183196
)
184197

185198
# Override cache_readonly bc Series is mutable

pandas/tests/series/test_api.py

-3
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,6 @@ def test_tab_completion(self):
247247
def test_tab_completion_with_categorical(self):
248248
# test the tab completion display
249249
ok_for_cat = [
250-
"name",
251-
"index",
252-
"categorical",
253250
"categories",
254251
"codes",
255252
"ordered",

0 commit comments

Comments
 (0)