Skip to content

BUG : Spearman correlation error generated from missing otypes in np.vectorize #61

@AndraIonescu

Description

@AndraIonescu

Description:
Python version: 3.8
numpy version: 1.22.3
ITMO_FS version: 0.3.3

When y.shape and x.shape are different, spearman_correlation fails because of missing "otypes" in np.vectorise.

This happens from np.vectorise - numpy/lib/function_base.py - _get_ufunc_and_otypes() - line 2365
otypes = ''.join([asarray(outputs[_k]).dtype.char for _k in range(nout)])

To Reproduce
Steps to reproduce the behaviour:

  1. I have X - a numpy array shape (1774, 601) with float and nan values.
  2. I have y - a numpy array shape (1774, ) with int values 0 and 1 only.
  3. Just run: spearman_corr(X, y)

Expected behaviour
Returns the scores and doesn't fail.

Desktop (please complete the following information):

  • OS: MacOS 13.2.1 (22D68)

Proposed fix:
I solved the issue by simply adding
otypes=[X.dtype]

So line 567 from filters/univariate/measures.py is now:
ranks_X[:, i] = np.vectorize(d.get, otypes=[X.dtype])(X[:, i])

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions