KrishnaswamyLab / phateR

PHATE dimensionality reduction method implemented in R
GNU General Public License v2.0
77 stars 9 forks source link

The arguments passed from within `R` are automatically converted to `float` by `reticulate` #54

Closed sameetmehta closed 3 years ago

sameetmehta commented 3 years ago

Describe the bug When you try to pass parameters to phate through R things get lost in translation.

To Reproduce

> phate_obj <- make_phate(sde_exp, use_inds, knn_max = 20)
   Calculating PHATE...
   Running PHATE on 433533 observations and 35 variables.
   Calculating graph and diffusion operator...
    Calculating KNN search...
    Calculated KNN search in 127.75 seconds.
   Calculated graph and diffusion operator in 127.78 seconds.
 Calculated PHATE in 127.78 seconds.
 Error in py_call_impl(callable, dots$args, dots$keywords) : 
   TypeError: n_neighbors does not take <class 'float'> value, enter integer value

 Detailed traceback: 
  File "/Users/sameet/YCGA/conda_envs/PHATE/lib/python3.8/site-packages/phate/phate.py", line 940, in fit_transform
    self.fit(X)
  File "/Users/sameet/YCGA/conda_envs/PHATE/lib/python3.8/site-packages/phate/phate.py", line 820, in fit
    self.graph = graphtools.Graph(
  File "/Users/sameet/YCGA/conda_envs/PHATE/lib/python3.8/site-packages/graphtools/api.py", line 288, in Graph
    return Graph(**params)
  File "/Users/sameet/YCGA/conda_envs/PHATE/lib/python3.8/site-packages/graphtools/graphs.py", line 132, in __init__
    super().__init__(data, n_pca=n_pca, **kwargs) 
  File "/Users/sameet/YCGA/conda_envs/PHATE/lib/python3.8/site-packages/graphtools/graphs.py", line 524, in __init__
    super().__init__(data, **kwargs)
  File "/Users/sameet/YCGA/conda_envs/PHATE/lib/python3.8/site-packages/graphtools/base.py", line 1019, in __init__
    super().__init__(data, **kwargs)
  F

Expected behavior It should convert the parameters correctly to type, and pass them on, rather than assuming everything is a float, or python should handle it better.

scottgigante commented 3 years ago

This error comes from the following:

  1. R's numeric is neither a float nor an int -- when converted to Python it is always converted to float, for some reason
  2. PHATE's knn_max is undocumented, so it's passed on through ... rather than manually converted to int like knn and other args.

You can solve this immediately by using knn_max = 20L or wait for me to push the fix.

scottgigante commented 3 years ago

Should be fixed on master. It'll be on CRAN in a few days.