diff --git a/pandas/core/methods/describe.py b/pandas/core/methods/describe.py index 944e28a9b0238..cc33c4e83a5ac 100644 --- a/pandas/core/methods/describe.py +++ b/pandas/core/methods/describe.py @@ -199,6 +199,9 @@ def _select_data(self) -> DataFrame: include=self.include, exclude=self.exclude, ) + if len(data.columns) == 0: + msg = "None of the included dtypes are present in the DataFrame" + raise ValueError(msg) return data diff --git a/pandas/tests/frame/methods/test_describe.py b/pandas/tests/frame/methods/test_describe.py index 50656ca85e90a..33f1d6dd5fe09 100644 --- a/pandas/tests/frame/methods/test_describe.py +++ b/pandas/tests/frame/methods/test_describe.py @@ -371,6 +371,13 @@ def test_describe_when_include_all_exclude_not_allowed(self, exclude): with pytest.raises(ValueError, match=msg): df.describe(include="all", exclude=exclude) + def test_describe_when_included_dtypes_not_present(self): + # GH#61863 + df = DataFrame({"a": [1, 2, 3]}) + msg = "None of the included dtypes are present in the DataFrame" + with pytest.raises(ValueError, match=msg): + df.describe(include=["datetime"]) + def test_describe_with_duplicate_columns(self): df = DataFrame( [[1, 1, 1], [2, 2, 2], [3, 3, 3]],