Minyus / pipelinex

PipelineX: Python package to build ML pipelines for experimentation with Kedro, MLflow, and more
https://pipelinex.readthedocs.io/
Other
221 stars 11 forks source link

Unable to bind `scipy.sparse.csr_matrix.log1p` #18

Open npow opened 1 year ago

npow commented 1 year ago

Hi, I encountered a strange issue trying to bind scipy.sparse.csr_matrix.log1p. It's saying ModuleNotFoundError: No module named 'scipy.sparse.csr_matrix', but it does exist?

from pipelinex import HatchDict
import yaml
from pprint import pprint  # pretty-print for clearer look

import scipy.sparse
assert scipy.sparse.csr_matrix.log1p

params_yaml = """
fn:
  =: scipy.sparse.csr_matrix.log1p
"""
parameters = yaml.safe_load(params_yaml)
fn = HatchDict(parameters).get("fn")
print(fn)
Minyus commented 1 year ago

Hi @npow ,

scipy.sparse.csr_matrix.log1p does not work because from scipy.sparse.csr_matrix import log1p does not work.

Instead, numpy.log1p should work because from numpy import log1p works. Can this be a workaround?

npow commented 1 year ago

numpy.log1p doesn't support sparse matrices. I've made a workaround by defining my own function which then calls scipy.sparse.csr_matrix.log1p but was wondering if there's a better way.