Skip to content

Commit cff4f36

Browse files
committed
BUG: Improve error message for unsupported datetime and timedelta dtypes in cov()
1 parent 079adc7 commit cff4f36

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pandas/core/frame.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@
105105
is_sequence,
106106
needs_i8_conversion,
107107
pandas_dtype,
108+
is_timedelta64_dtype,
109+
is_datetime64_any_dtype,
108110
)
109111
from pandas.core.dtypes.concat import concat_compat
110112
from pandas.core.dtypes.dtypes import (
@@ -11267,10 +11269,11 @@ def cov(
1126711269
c -0.150812 0.191417 0.895202
1126811270
"""
1126911271
data = self._get_numeric_data() if numeric_only else self
11270-
if data.select_dtypes(include=[np.datetime64, np.timedelta64]).shape[1] > 0:
11272+
dtypes = [blk.dtype for blk in self._mgr.blocks]
11273+
if any(is_datetime64_any_dtype(d) or is_timedelta64_dtype(d) for d in dtypes):
1127111274
msg = (
11272-
"DataFrame contains columns with dtype datetime64[ns] "
11273-
"or timedelta64[ns], which are not supported for cov."
11275+
"DataFrame contains columns with dtype datetime64 "
11276+
"or timedelta64, which are not supported for cov."
1127411277
)
1127511278
raise TypeError(msg)
1127611279
cols = data.columns

0 commit comments

Comments
 (0)