From 8dac43f00e64949ffc6d8a35cfe28ba94b5445ef Mon Sep 17 00:00:00 2001 From: Verena Neufeld Date: Tue, 28 Apr 2020 15:04:01 +0200 Subject: [PATCH 1/2] stop using .ix --- tools/pyhande/pyhande/analysis.py | 6 +++--- tools/pyhande/pyhande/lazy.py | 10 +++++----- tools/pyhande/pyhande/testcode.py | 5 ++--- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tools/pyhande/pyhande/analysis.py b/tools/pyhande/pyhande/analysis.py index 1a5c0cd2f..d7a179de6 100644 --- a/tools/pyhande/pyhande/analysis.py +++ b/tools/pyhande/pyhande/analysis.py @@ -53,8 +53,8 @@ def projected_energy(reblock_data, covariance, data_length, :func:`pyblock.pd_utils.reblock` for producing the input parameters. ''' - proje_sum = reblock_data.ix[:, sum_key] - ref_pop = reblock_data.ix[:, ref_key] + proje_sum = reblock_data[sum_key] + ref_pop = reblock_data[ref_key] proje_ref_cov = covariance.xs(ref_key, level=1)[sum_key] proje = pyblock.error.ratio(proje_sum, ref_pop, proje_ref_cov, data_length) proje.columns = pd.MultiIndex.from_tuples( @@ -90,7 +90,7 @@ def qmc_summary(data, keys=('\sum H_0j N_j', 'N_0', 'Shift', 'Proj. Energy'), (opt_data, no_opt) = ([], []) for col in keys: if col in data: - summary = pyblock.pd_utils.reblock_summary(data.ix[:, col]) + summary = pyblock.pd_utils.reblock_summary(data[col]) if summary.empty: no_opt.append(col) else: diff --git a/tools/pyhande/pyhande/lazy.py b/tools/pyhande/pyhande/lazy.py index 19687f75f..3f5b90f99 100644 --- a/tools/pyhande/pyhande/lazy.py +++ b/tools/pyhande/pyhande/lazy.py @@ -68,7 +68,7 @@ def find_starting_iteration_mser_min(data, md, start_max_frac=0.9, n_blocks=100, if end is None: end = data['iterations'].iloc[-1] before_end_indx = data['iterations'] <= end - data_before_end = data.ix[before_end_indx] + data_before_end = data[before_end_indx] list = data_before_end['Proj. Energy'] n_data=len(list) @@ -128,7 +128,7 @@ def lazy_hybrid(calc, md, start=0, end=None, batch_size=1): if end is None: end = calc['iterations'].iloc[-1] before_end_indx = calc['iterations'] <= end - data_before_end = calc.ix[before_end_indx] + data_before_end = calc[before_end_indx] after_start_indx = data_before_end['iterations'] >= start calc_tr = data_before_end[after_start_indx] @@ -392,7 +392,7 @@ def lazy_block(calc, md, start=0, end=None, select_function=None, if extract_rep_loop_time: to_block.append('time') - mc_data = calc.ix[indx, to_block] + mc_data = calc.loc[indx, to_block] if mc_data['Shift'].iloc[0] == mc_data['Shift'].iloc[1]: if calc['Shift'][~indx].iloc[-1] == mc_data['Shift'].iloc[0]: warnings.warn('The blocking analysis starts from before the shift ' @@ -417,7 +417,7 @@ def lazy_block(calc, md, start=0, end=None, select_function=None, if calc_inefficiency: # Calculate quantities needed for the inefficiency. dtau = md['qmc']['tau'] - reblocked_iters = calc.ix[indx, 'iterations'] + reblocked_iters = calc.loc[indx, 'iterations'] N = reblocked_iters.iloc[-1] - reblocked_iters.iloc[0] # This returns a data frame with inefficiency data from the @@ -636,7 +636,7 @@ def find_starting_iteration(data, md, frac_screen_interval=300, # Default end is the last iteration. end = data['iterations'].iloc[-1] before_end_indx = data['iterations'] <= end - data_before_end = data.ix[before_end_indx] + data_before_end = data[before_end_indx] # Find the point the shift began to vary. variable_shift = data_before_end['Shift'] != data_before_end['Shift'].iloc[0] diff --git a/tools/pyhande/pyhande/testcode.py b/tools/pyhande/pyhande/testcode.py index 0801ece33..c8ee4c184 100644 --- a/tools/pyhande/pyhande/testcode.py +++ b/tools/pyhande/pyhande/testcode.py @@ -46,13 +46,12 @@ def extract_test_data(fname, underscore=True): # Compare all bar the first entry (which contains a legitimate # NaN in the standard error, which is not handled well by # testcode). - indxs = range(len(data))[1:] - test_data = data.ix[indxs] + test_data = data.iloc[1:] output[metadata['calc_type'] + calc_ind] = test_data elif len(data) > 10: # Compare every 1/4 of (non-trivial) QMC calculation... indxs = [0] + [int((i*len(data))/4)-1 for i in range(1,5)] - test_data = data.ix[indxs] + test_data = data.iloc[indxs] output[metadata['calc_type'] + calc_ind] = test_data else: output[metadata['calc_type'] + calc_ind] = data From a66ef806eabe7a854088db8ce03ae184aa53ead9 Mon Sep 17 00:00:00 2001 From: Verena Neufeld Date: Tue, 28 Apr 2020 16:34:21 +0200 Subject: [PATCH 2/2] python 3 compatible integer division + deprecated .as_matrix() --- tools/pyhande/pyhande/lazy.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/pyhande/pyhande/lazy.py b/tools/pyhande/pyhande/lazy.py index 3f5b90f99..f167bb1b4 100644 --- a/tools/pyhande/pyhande/lazy.py +++ b/tools/pyhande/pyhande/lazy.py @@ -136,8 +136,8 @@ def lazy_hybrid(calc, md, start=0, end=None, batch_size=1): #list = calc_tr['Proj. Energy'].as_matrix() #n_data = len(list) - list_org = calc_tr['Proj. Energy'].as_matrix() - n_data = len(list_org) / batch_size + list_org = calc_tr['Proj. Energy'].values + n_data = len(list_org) // batch_size list = [0]*n_data for i in range(n_data): list[i] = numpy.mean(list_org[i*batch_size:(i+1)*batch_size])