Skip to content

replace NotImplementedError with AttributeError #31549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
from pandas.io.formats.printing import pprint_thing
import pandas.plotting


# Customized "cover all bases" local Exception
class DataFrameError(NotImplementedError, TypeError, AttributeError):
pass


if TYPE_CHECKING:
from pandas.core.groupby.generic import DataFrameGroupBy
from pandas.io.formats.style import Styler
Expand Down Expand Up @@ -411,7 +417,9 @@ def _constructor(self) -> Type["DataFrame"]:

@property
def _constructor_expanddim(self):
raise NotImplementedError("Not supported for DataFrames!")
raise DataFrameError(
"Property 'constructor_expanddim' is not supported for DataFrames!"
)

# ----------------------------------------------------------------------
# Constructors
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/frame/test_subclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
from pandas import DataFrame, Index, MultiIndex, Series
import pandas._testing as tm

import inspect


class TestDataFrameSubclassing:

def test_get_members():
inspect.getmembers(pd.DataFrame())

def test_frame_subclassing_and_slicing(self):
# Subclass frame and ensure it returns the right class on slicing it
# In reference to PR 9632
Expand Down