Skip to content

inspect-safety for DataFrame._constructor_expanddim #33628

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

Merged
merged 4 commits into from
Apr 21, 2020
Merged
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
7 changes: 6 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion pandas/tests/frame/test_api.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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))