diff --git a/doc/source/whatsnew/v1.2.1.rst b/doc/source/whatsnew/v1.2.1.rst index c630fc26a93a2..769c195229bbd 100644 --- a/doc/source/whatsnew/v1.2.1.rst +++ b/doc/source/whatsnew/v1.2.1.rst @@ -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`) - .. --------------------------------------------------------------------------- diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e43edf1e6577e..2f7e78d696d7c 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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 diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 157c8687808b3..a7e2fa760b7e4 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -1,7 +1,6 @@ from copy import deepcopy import inspect import pydoc -import warnings import numpy as np import pytest @@ -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)