PERF: Series.corr/Series.cov for EA dtypes by lukemanley · Pull Request #52502 · pandas-dev/pandas (original) (raw)

any chance this gets weird if we have non-numeric?

This raises for non-numeric that cannot be cast to float (same as behavior as main branch):

ser = pd.Series(["a", "b"])
ser.corr(ser)

# ValueError: could not convert string to float: 'a'

It allows non-numeric that can be cast to float (same behavior as main branch):

ser = pd.Series(["1", "2"])
ser.corr(ser)

# 0.9999999999999999

is this the right thing to do if we have NAs?

NAs get dropped either way in the underlying nanops.py functions nancorr and nancov.

FYI, this is the same approach used in DataFrame.corr:

mat = data.to_numpy(dtype=float, na_value=np.nan, copy=False)