Skip to content

Commit 6210077

Browse files
authored
DEPR: Hide deprecated attrs _AXIS_NAMES & _AXIS_NUMBERS (#38740)
1 parent 760c6ff commit 6210077

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

doc/source/whatsnew/v1.2.1.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ including other versions of pandas.
1414

1515
Fixed regressions
1616
~~~~~~~~~~~~~~~~~
17-
-
17+
- 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`)
1818
-
1919

2020
.. ---------------------------------------------------------------------------

pandas/core/generic.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ class NDFrame(PandasObject, SelectionMixin, indexing.IndexingMixin):
178178
]
179179
_internal_names_set: Set[str] = set(_internal_names)
180180
_accessors: Set[str] = set()
181-
_hidden_attrs: FrozenSet[str] = frozenset(["get_values", "tshift"])
181+
_hidden_attrs: FrozenSet[str] = frozenset(
182+
["_AXIS_NAMES", "_AXIS_NUMBERS", "get_values", "tshift"]
183+
)
182184
_metadata: List[str] = []
183185
_is_copy = None
184186
_mgr: BlockManager

pandas/tests/frame/test_api.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from copy import deepcopy
22
import inspect
33
import pydoc
4-
import warnings
54

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

333-
@skip_if_no("jinja2")
334332
def test_constructor_expanddim_lookup(self):
335333
# GH#33628 accessing _constructor_expanddim should not
336334
# raise NotImplementedError
337335
df = DataFrame()
338336

339-
with warnings.catch_warnings(record=True) as wrn:
340-
# _AXIS_NUMBERS, _AXIS_NAMES lookups
341-
inspect.getmembers(df)
342-
343-
# some versions give FutureWarning, others DeprecationWarning
344-
assert len(wrn)
345-
assert any(x.category in [FutureWarning, DeprecationWarning] for x in wrn)
346-
347337
with pytest.raises(NotImplementedError, match="Not supported for DataFrames!"):
348338
df._constructor_expanddim(np.arange(27).reshape(3, 3, 3))
339+
340+
@skip_if_no("jinja2")
341+
def test_inspect_getmembers(self):
342+
# GH38740
343+
df = DataFrame()
344+
with tm.assert_produces_warning(None):
345+
inspect.getmembers(df)

0 commit comments

Comments
 (0)