Skip to content

Commit d714b90

Browse files
KhemkaranKhemkaran
authored andcommitted
none of the included dtypes present in df will raise clear error message
1 parent 1d153bb commit d714b90

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pandas/core/methods/describe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ def describe(self, percentiles: Sequence[float] | np.ndarray) -> DataFrame:
172172
ldesc.append(describe_func(series, percentiles))
173173

174174
col_names = reorder_columns(ldesc)
175+
if len(ldesc) == 0:
176+
raise ValueError("None of the included dtypes are present in the DataFrame")
175177
d = concat(
176178
[x.reindex(col_names) for x in ldesc],
177179
axis=1,

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 = pd.DataFrame({"a": [1, 2, 3]})
377+
msg = "None of the included dtypes are present in the DataFrame"
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)