From 2fbe80138ffa4cc0f0c1e444361dae0ef6b0dbba Mon Sep 17 00:00:00 2001
From: jbrockmendel <jbrockmendel@gmail.com>
Date: Sat, 18 Apr 2020 07:06:53 -0700
Subject: [PATCH 1/2] inspect-safety for DataFrame._constructor_expanddim

---
 pandas/core/frame.py           |  7 ++++++-
 pandas/tests/frame/test_api.py | 10 ++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)

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..c71d35af74d64 100644
--- a/pandas/tests/frame/test_api.py
+++ b/pandas/tests/frame/test_api.py
@@ -1,5 +1,6 @@
 from copy import deepcopy
 import datetime
+import inspect
 import pydoc
 
 import numpy as np
@@ -569,3 +570,12 @@ def test_cache_on_copy(self):
 
         assert df["a"].values[0] == -1
         tm.assert_frame_equal(df, DataFrame({"a": [-1], "x": [0], "y": [0]}))
+
+    def test_constructor_expanddim_lookup(self):
+        # 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))

From 79e4bf57d37d88d13f8e7fd5c02a2a1ffff786c2 Mon Sep 17 00:00:00 2001
From: jbrockmendel <jbrockmendel@gmail.com>
Date: Mon, 20 Apr 2020 12:35:33 -0700
Subject: [PATCH 2/2] troubleshoot CI

---
 pandas/tests/frame/test_api.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pandas/tests/frame/test_api.py b/pandas/tests/frame/test_api.py
index c71d35af74d64..5cf74d3205a13 100644
--- a/pandas/tests/frame/test_api.py
+++ b/pandas/tests/frame/test_api.py
@@ -7,7 +7,7 @@
 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
@@ -571,8 +571,10 @@ 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):
-        # accessing _constructor_expanddim should not raise NotImplementedError
+        # GH#33628 accessing _constructor_expanddim should not
+        #  raise NotImplementedError
         df = DataFrame()
 
         inspect.getmembers(df)