From aa8fdedd36b43b040b5765a795fe042a4bfb8203 Mon Sep 17 00:00:00 2001 From: tp Date: Mon, 28 Dec 2020 02:50:27 +0000 Subject: [PATCH 1/5] DEPR: Hide deprecated attrs _AXIS_NAMES & _AXIS_NUMBERS --- pandas/core/generic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index bdb28c10a0ad2..b34d23bee8b8a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -178,7 +178,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 From 1f25122e5d2214fe0fe195588fb33a97e53709c5 Mon Sep 17 00:00:00 2001 From: tp Date: Mon, 28 Dec 2020 03:34:48 +0000 Subject: [PATCH 2/5] fix test --- pandas/tests/frame/test_api.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 157c8687808b3..33381f2f3ed9b 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -337,12 +337,10 @@ def test_constructor_expanddim_lookup(self): 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) + # some versions may give FutureWarning, others DeprecationWarning + assert not len(wrn) with pytest.raises(NotImplementedError, match="Not supported for DataFrames!"): df._constructor_expanddim(np.arange(27).reshape(3, 3, 3)) From fdfafdb90a69930e0d8792595eedc9d385fb7aad Mon Sep 17 00:00:00 2001 From: tp Date: Mon, 28 Dec 2020 10:46:36 +0000 Subject: [PATCH 3/5] make test for inspect.getmembers separate --- pandas/tests/frame/test_api.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 33381f2f3ed9b..5b68dc334828a 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -336,11 +336,14 @@ def test_constructor_expanddim_lookup(self): # raise NotImplementedError df = DataFrame() + with pytest.raises(NotImplementedError, match="Not supported for DataFrames!"): + df._constructor_expanddim(np.arange(27).reshape(3, 3, 3)) + + def test_inspect_getmembers(self): + # GH38740 + df = DataFrame() + with warnings.catch_warnings(record=True) as wrn: inspect.getmembers(df) - # some versions may give FutureWarning, others DeprecationWarning assert not len(wrn) - - with pytest.raises(NotImplementedError, match="Not supported for DataFrames!"): - df._constructor_expanddim(np.arange(27).reshape(3, 3, 3)) From d2d88af873f3f57b11e216d99d853dff4614b867 Mon Sep 17 00:00:00 2001 From: tp Date: Mon, 28 Dec 2020 11:45:35 +0000 Subject: [PATCH 4/5] move skip_if_no --- pandas/tests/frame/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index 5b68dc334828a..f0f5d6e8ed137 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -330,7 +330,6 @@ 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 @@ -339,6 +338,7 @@ def test_constructor_expanddim_lookup(self): 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() From 6a78bc9f33f8342fe897c2ca97f7a9d3e4253cef Mon Sep 17 00:00:00 2001 From: tp Date: Mon, 28 Dec 2020 17:42:21 +0000 Subject: [PATCH 5/5] update --- doc/source/whatsnew/v1.2.1.rst | 2 +- pandas/tests/frame/test_api.py | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) 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/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index f0f5d6e8ed137..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 @@ -342,8 +341,5 @@ def test_constructor_expanddim_lookup(self): def test_inspect_getmembers(self): # GH38740 df = DataFrame() - - with warnings.catch_warnings(record=True) as wrn: + with tm.assert_produces_warning(None): inspect.getmembers(df) - - assert not len(wrn)