diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 85bb47485a2e7..56a9b57a8e720 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -422,7 +422,12 @@ def _constructor(self) -> Type["DataFrame"]: @property def _constructor_expanddim(self): - raise NotImplementedError("Not supported for DataFrames!") + # GH#31549 raising NotImplementedError on a property causes trouble + # for `inspect` + def constructor(*args, **kwargs): + raise NotImplementedError("Not supported for DataFrames!") + + return constructor # ---------------------------------------------------------------------- # Constructors diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py index ec8613faaa663..5cf74d3205a13 100644 --- a/pandas/tests/frame/test_api.py +++ b/pandas/tests/frame/test_api.py @@ -1,12 +1,13 @@ from copy import deepcopy import datetime +import inspect import pydoc import numpy as np import pytest from pandas.compat import PY37 -from pandas.util._test_decorators import async_mark +from pandas.util._test_decorators import async_mark, skip_if_no import pandas as pd from pandas import Categorical, DataFrame, Series, compat, date_range, timedelta_range @@ -569,3 +570,14 @@ def test_cache_on_copy(self): assert df["a"].values[0] == -1 tm.assert_frame_equal(df, DataFrame({"a": [-1], "x": [0], "y": [0]})) + + @skip_if_no("jinja2") + def test_constructor_expanddim_lookup(self): + # GH#33628 accessing _constructor_expanddim should not + # raise NotImplementedError + df = DataFrame() + + inspect.getmembers(df) + + with pytest.raises(NotImplementedError, match="Not supported for DataFrames!"): + df._constructor_expanddim(np.arange(27).reshape(3, 3, 3))