miRTop / mirtop

command lines tool to annotate miRNAs with a standard mirna/isomir naming
https://mirtop.readthedocs.org
MIT License
18 stars 21 forks source link

Pandas update breaks mirtop stats #78

Open jonahcullen opened 1 year ago

jonahcullen commented 1 year ago

Expected behavior and actual behavior.

Expected behavior is to run mirtop stats following mirtop gff. With the April 2023 update of pandas to v2.0.0, the append method of a DataFrame has been removed.

Traceback (most recent call last):
  File "/opt/conda/envs/small/bin/mirtop", line 10, in <module>
    sys.exit(main())
  File "/opt/conda/envs/small/lib/python3.10/site-packages/mirtop/command_line.py", line 34, in main
    stats(kwargs["args"])
  File "/opt/conda/envs/small/lib/python3.10/site-packages/mirtop/gff/stats.py", line 38, in stats
    out.append(_calc_stats(fn))
  File "/opt/conda/envs/small/lib/python3.10/site-packages/mirtop/gff/stats.py", line 82, in _calc_stats
    df = _summary(lines)
  File "/opt/conda/envs/small/lib/python3.10/site-packages/mirtop/gff/stats.py", line 130, in _summary
    df_sum = _add_missing(df_sum)
  File "/opt/conda/envs/small/lib/python3.10/site-packages/mirtop/gff/stats.py", line 111, in _add_missing
    df = df.append(df2, ignore_index = True)
  File "/opt/conda/envs/small/lib/python3.10/site-packages/pandas/core/generic.py", line 5989, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'append'. Did you mean: '_append'?

You can see the issue in the _add_missing function

def _add_missing(df):
    # ref_miRNA_mean
    category = "ref_miRNA_mean"
    if sum(df['category']==category) == 0:
        df2 = {'category': category, 'sample': df['sample'].iat[0], 'counts': 0}
        df = df.append(df2, ignore_index = True)
    category = "isomiR_sum"
    if sum(df['category']==category) == 0:
        df2 = {'category': category, 'sample': df['sample'].iat[0], 'counts': 0}
        df = df.append(df2, ignore_index = True)

I have not checked if it occurs elsewhere.

Steps to reproduce the problem.

Installing mirtop as described with conda will use the latest pandas (v2.0.1) and cause the above error.

Specifications like the version of the project, operating system, or hardware.

As a temporary workaround, specifying the pandas version fixes the issue

mamba create -n mirtop -c conda-forge -c bioconda mirtop=0.4.25 pandas=1.5.3