Tomoki-YAMASHITA / CrySPY

CrySPY is a crystal structure prediction tool written in Python.
https://tomoki-yamashita.github.io/CrySPY_doc
MIT License
107 stars 38 forks source link

concat method is used due to the deprecated frame.append method #18

Closed yw-fang closed 2 years ago

yw-fang commented 2 years ago

Hi, Yamashita-san

I noticed the warning "FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version." these days when I used the latest two versions of CrySPY to generate the structures in the next generation. I employed "concat" method instead of the "append" method for your consideration. A demo example is shown below to compare the two methods.

Best wishes Yuewen Fang

The "append" method in CrySPY

import pickle 
import pandas as pd

def load_ea_data():
    with open('./EA_data.pkl', 'rb') as f:
        ea_data = pickle.load(f)
    return ea_data

elite_struc, elite_fitness, ea_info, ea_origin = load_ea_data()
print(ea_info)
tmp_info = pd.Series([9999, 50, 9999, 9999, 9999, 9999, 9999,'equal', 'TNM'], index=ea_info.columns)
ea_info = ea_info.append(tmp_info, ignore_index=True)
print(ea_info)

The output is

Gen Population Crossover Permutation Strain Random Elite crs_lat slct_func
0   1         50         0           0      0     50     0   equal       TNM
1   2         50        20           5     10     15     5   equal       TNM
2   3         50        25           5     10     10     5   equal       TNM
3   4         50        25           5     10     10     5   equal       TNM
4   5         50        25           5     10     10     5   equal       TNM
5   6         50        25           5     10     10     5   equal       TNM
6   7         50        25           5     10     10     5   equal       TNM
    Gen Population Crossover Permutation Strain Random Elite crs_lat slct_func
0     1         50         0           0      0     50     0   equal       TNM
1     2         50        20           5     10     15     5   equal       TNM
2     3         50        25           5     10     10     5   equal       TNM
3     4         50        25           5     10     10     5   equal       TNM
4     5         50        25           5     10     10     5   equal       TNM
5     6         50        25           5     10     10     5   equal       TNM
6     7         50        25           5     10     10     5   equal       TNM
7  9999         50      9999        9999   9999   9999  9999   equal       TNM
/tmp/ipykernel_55523/2456999282.py:12: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
  ea_info = ea_info.append(tmp_info, ignore_index=True)

The "contact" method in CrySPY

import pickle 
import pandas as pd

def load_ea_data():
    with open('./EA_data.pkl', 'rb') as f:
        ea_data = pickle.load(f)
    return ea_data

elite_struc, elite_fitness, ea_info, ea_origin = load_ea_data()
print(ea_info)

tmp_info = pd.Series([9999, 50, 9999, 9999, 9999, 9999, 9999,'equal', 'TNM'], index=ea_info.columns)
ea_info = pd.concat([ea_info, pd.DataFrame(tmp_info).T], axis=0, ignore_index=True)
print(ea_info)

The output is

Gen Population Crossover Permutation Strain Random Elite crs_lat slct_func
0   1         50         0           0      0     50     0   equal       TNM
1   2         50        20           5     10     15     5   equal       TNM
2   3         50        25           5     10     10     5   equal       TNM
3   4         50        25           5     10     10     5   equal       TNM
4   5         50        25           5     10     10     5   equal       TNM
5   6         50        25           5     10     10     5   equal       TNM
6   7         50        25           5     10     10     5   equal       TNM
    Gen Population Crossover Permutation Strain Random Elite crs_lat slct_func
0     1         50         0           0      0     50     0   equal       TNM
1     2         50        20           5     10     15     5   equal       TNM
2     3         50        25           5     10     10     5   equal       TNM
3     4         50        25           5     10     10     5   equal       TNM
4     5         50        25           5     10     10     5   equal       TNM
5     6         50        25           5     10     10     5   equal       TNM
6     7         50        25           5     10     10     5   equal       TNM
7  9999         50      9999        9999   9999   9999  9999   equal       TNM
​
Tomoki-YAMASHITA commented 2 years ago

@yw-fang

Thank you for the tip.

I'll modify the following a bit more

tmp_info = pd.Series([9999, 50, 9999, 9999, 9999, 9999, 9999,'equal', 'TNM'], index=ea_info.columns)
ea_info = pd.concat([ea_info, pd.DataFrame(tmp_info).T], axis=0, ignore_index=True)

like this:

tmp_info = pd.DataFrame([[9999, 50, 9999, 9999, 9999, 9999, 9999,'equal', 'TNM']], columns=ea_info.columns)
ea_info = pd.concat([ea_info, tmp_info], axis=0, ignore_index=True)

I will skip to merge because there are other corrections in addition to ea_next_gen.py, and reflect the fix in the next version.

yw-fang commented 2 years ago

Sure! No problem to skip it. Your revision is cleaner than mine if tmp_info is defined as a dataframe at first. Since you have noticed this issue, II'll close this pull request here. Thanks!