Skip to content

Commit

Permalink
Backport PR pandas-dev#38740: DEPR: Hide deprecated attrs _AXIS_NAMES…
Browse files Browse the repository at this point in the history
… & _AXIS_NUMBERS (pandas-dev#38755)

Co-authored-by: Terji Petersen <contribute@tensortable.com>
  • Loading branch information
meeseeksmachine and topper-123 authored Dec 28, 2020
1 parent d095e4c commit 6083750
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ including other versions of pandas.

Fixed regressions
~~~~~~~~~~~~~~~~~
-
- The deprecated attributes ``_AXIS_NAMES`` and ``_AXIS_NUMBERS`` of :class:`DataFrame` and :class:`Series` will no longer show up in ``dir`` or ``inspect.getmembers`` calls (:issue:`38740`)
-

.. ---------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ class NDFrame(PandasObject, SelectionMixin, indexing.IndexingMixin):
]
_internal_names_set: Set[str] = set(_internal_names)
_accessors: Set[str] = set()
_hidden_attrs: FrozenSet[str] = frozenset(["get_values", "tshift"])
_hidden_attrs: FrozenSet[str] = frozenset(
["_AXIS_NAMES", "_AXIS_NUMBERS", "get_values", "tshift"]
)
_metadata: List[str] = []
_is_copy = None
_mgr: BlockManager
Expand Down
17 changes: 7 additions & 10 deletions pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from copy import deepcopy
import inspect
import pydoc
import warnings

import numpy as np
import pytest
Expand Down Expand Up @@ -330,19 +329,17 @@ def test_set_flags(self, allows_duplicate_labels, frame_or_series):
result.iloc[key] = 10
assert obj.iloc[key] == 0

@skip_if_no("jinja2")
def test_constructor_expanddim_lookup(self):
# GH#33628 accessing _constructor_expanddim should not
# raise NotImplementedError
df = DataFrame()

with warnings.catch_warnings(record=True) as wrn:
# _AXIS_NUMBERS, _AXIS_NAMES lookups
inspect.getmembers(df)

# some versions give FutureWarning, others DeprecationWarning
assert len(wrn)
assert any(x.category in [FutureWarning, DeprecationWarning] for x in wrn)

with pytest.raises(NotImplementedError, match="Not supported for DataFrames!"):
df._constructor_expanddim(np.arange(27).reshape(3, 3, 3))

@skip_if_no("jinja2")
def test_inspect_getmembers(self):
# GH38740
df = DataFrame()
with tm.assert_produces_warning(None):
inspect.getmembers(df)

0 comments on commit 6083750

Please sign in to comment.