Skip to content

Commit ff8ac64

Browse files
khemkaran10Khemkaranmroeschke
authored
BUG FIX: None of the included dtypes present in df will raise ValueError with clear error message. (#61871)
Co-authored-by: Khemkaran <[email protected]> Co-authored-by: Matthew Roeschke <[email protected]>
1 parent ad0ec21 commit ff8ac64

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

pandas/core/methods/describe.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def _select_data(self) -> DataFrame:
199199
include=self.include,
200200
exclude=self.exclude,
201201
)
202+
if len(data.columns) == 0:
203+
msg = "No columns match the specified include or exclude data types"
204+
raise ValueError(msg)
202205
return data
203206

204207

pandas/tests/frame/methods/test_describe.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ def test_describe_when_include_all_exclude_not_allowed(self, exclude):
371371
with pytest.raises(ValueError, match=msg):
372372
df.describe(include="all", exclude=exclude)
373373

374+
def test_describe_when_included_dtypes_not_present(self):
375+
# GH#61863
376+
df = DataFrame({"a": [1, 2, 3]})
377+
msg = "No columns match the specified include or exclude data types"
378+
with pytest.raises(ValueError, match=msg):
379+
df.describe(include=["datetime"])
380+
374381
def test_describe_with_duplicate_columns(self):
375382
df = DataFrame(
376383
[[1, 1, 1], [2, 2, 2], [3, 3, 3]],

0 commit comments

Comments
 (0)