gagneurlab/OUTRIDER

Error in findEncodingDim: deprecated pandas.DataFrame.append pandas>=2.0

Opened this issue · 1 comments

I get an error when trying to find the best q parameter:

library(reticulate)
library(OUTRIDER)

reticulate::use_virtualenv(virtualenv = "/home/mpauper/.cache/pypoetry/virtualenvs/nmd-project-NMwd2pX9-py3.10")

ex <- makeExampleProtriderDataSet()
ex <- findEncodingDim(ex)

Output:

Mon Oct 30 16:46:08 2023:  Applying preprocessing function ...
        Mon Oct 30 16:46:08 2023: SizeFactor estimation ...
Mon Oct 30 16:46:08 2023: Preprocessing ...
        Mon Oct 30 16:46:08 2023: SizeFactor estimation ...
Mon Oct 30 16:46:08 2023: Controlling for confounders ...
Using specified q = 5
Mon Oct 30 16:46:08 2023: Using the python autoencoder implementation for controlling.
Connecting to the py_outrider python package using reticulate (useBasilisk = FALSE)... 
In case of errors, please make sure to specify the right python binary when loading R.
If you rather want us to automatically setup a conda environment with 'py_outrider'
installed using the 'basilisk' package, please use the argument 'useBasilisk = TRUE'.
### Mon 30 Oct 2023 04:46:08 PM CET   parser check for correct input arguments
### Mon 30 Oct 2023 04:46:08 PM CET   parsed the following settings:
{'prepro_func': 'none', 'sf_norm': True, 'data_trans': 'none', 'centering': True, 'noise_factor': 0.0, 'encod_dim': 5, 'latent_space_model': 'AE', 'decoder_model': 'AE', 'dispersion_model': 'ML', 'loss_distribution': 'gaussian', 'covariates': None, 'optimizer': 'lbfgs', 'parallelize_decoder_by_feature': True, 'batch_size': None, 'nr_latent_space_features': None, 'num_cpus': 4, 'float_type': 'float64', 'seed': 7, 'iterations': 15, 'convergence': 1e-05, 'verbose': False, 'distribution': 'gaussian', 'fdr_method': 'fdr_by', 'effect_type': ['zscores', 'fold_change', 'delta']}
### Mon 30 Oct 2023 04:46:08 PM CET   create adata object out of input data
### Mon 30 Oct 2023 04:46:08 PM CET   Preprocessing input ...
/home/mpauper/.cache/pypoetry/virtualenvs/nmd-project-NMwd2pX9-py3.10/lib/python3.10/site-packages/py_outrider/preprocess.py:62: RuntimeWarning: invalid value encountered in divide
  adata.X = adata.X / np.expand_dims(sf, 1)
No physical GPUs detected
### Mon 30 Oct 2023 04:46:08 PM CET   Start model fitting
### Mon 30 Oct 2023 04:46:08 PM CET   Initializing the encoder ...
### Mon 30 Oct 2023 04:46:09 PM CET   Initializing the decoder ...
Error in stop(.error_bplist(res)) : bad error message
> 

Do you have an idea on what is going wrong?

The issue comes from Pandas version 2.0 and above and is related to the loss_list.py code of py_outrider which tries to append to a DataFrame, but append is deprecated (use concat instead) since pandas 2.0. This is the relevant line in loss_list.py.

I could solve it by changing the line to:
self.loss_summary = pd.concat([self.loss_summary, loss_row], ignore_index=False)

It would be great if the code was updated to be compatible with newer versions of Pandas otherwise feel free to close the issue.