def validate_from_ppc(ppc_net, net, pf_type='runpp', max_diff_values={'bus_vm_pu': 1e-06, 'bus_va_degree': 1e-05, 'branch_p_mw': 1e-06, 'branch_q_mvar': 1e-06, 'gen_p_mw': 1e-06, 'gen_q_mvar': 1e-06}, run=True):
    '\n    This function validates the pypower case files to pandapower net structure conversion via a     comparison of loadflow calculation results. (Hence the opf cost conversion is not validated.)\n\n    INPUT:\n\n        **ppc_net** - The pypower case file, which must already contain the pypower powerflow\n            results or pypower must be importable.\n\n        **net** - The pandapower network.\n\n    OPTIONAL:\n\n        **pf_type** ("runpp", string) - Type of validated power flow. Possible are ("runpp",\n            "rundcpp", "runopp", "rundcopp")\n\n        **max_diff_values** - Dict of maximal allowed difference values. The keys must be\n        \'vm_pu\', \'va_degree\', \'p_branch_mw\', \'q_branch_mvar\', \'p_gen_mw\' and \'q_gen_mvar\' and\n        the values floats.\n\n        **run** (True, bool or list of two bools) - changing the value to False avoids trying to run\n            (optimal) loadflows. Giving a list of two bools addresses first pypower and second\n            pandapower.\n\n    OUTPUT:\n\n        **conversion_success** - conversion_success is returned as False if pypower or pandapower\n        cannot calculate a powerflow or if the maximum difference values (max_diff_values )\n        cannot be hold.\n\n    EXAMPLE:\n\n        import pandapower.converter as pc\n\n        net = cv.from_ppc(ppc_net, f_hz=50)\n\n        conversion_success = cv.validate_from_ppc(ppc_net, net)\n\n    NOTE:\n\n        The user has to take care that the loadflow results already are included in the provided         ppc_net or pypower is importable.\n    '
    if ('opp' in pf_type):
        if (not (len(net.polynomial_cost) | len(net.piecewise_linear_cost))):
            if ('gencost' in ppc_net):
                if (not len(ppc_net['gencost'])):
                    logger.debug('ppc and pandapower net do not include cost information.')
                    return True
                else:
                    logger.error('The pandapower net does not include cost information.')
                    return False
            else:
                logger.debug('ppc and pandapower net do not include cost information.')
                return True
    run = ([run, run] if isinstance(run, bool) else run)
    if (pypower_import and run[0]):
        try:
            if (pf_type == 'runpp'):
                ppc_net = runpf.runpf(ppc_net, ppopt)[0]
            elif (pf_type == 'rundcpp'):
                ppc_net = rundcpf.rundcpf(ppc_net, ppopt)[0]
            elif (pf_type == 'runopp'):
                ppc_net = runopf.runopf(ppc_net, ppopt)
            elif (pf_type == 'rundcopp'):
                ppc_net = rundcopf.rundcopf(ppc_net, ppopt)
            else:
                raise ValueError(('The pf_type %s is unknown' % pf_type))
        except:
            logger.debug('The pypower run did not work.')
    ppc_success = True
    if ('success' in ppc_net.keys()):
        if (ppc_net['success'] != 1):
            ppc_success = False
            logger.error(('The given ppc data indicates an unsuccessful pypower powerflow: ' + "'ppc_net['success'] != 1'"))
    if (ppc_net['branch'].shape[1] < 17):
        ppc_success = False
        logger.error('The shape of given ppc data indicates missing pypower powerflow results.')
    if run[1]:
        if (pf_type == 'runpp'):
            try:
                pp.runpp(net, init='dc', calculate_voltage_angles=True, trafo_model='pi')
            except pp.LoadflowNotConverged:
                try:
                    pp.runpp(net, calculate_voltage_angles=True, init='flat', trafo_model='pi')
                except pp.LoadflowNotConverged:
                    try:
                        pp.runpp(net, trafo_model='pi', calculate_voltage_angles=False)
                        if ('bus_va_degree' in max_diff_values.keys()):
                            max_diff_values['bus_va_degree'] = (100.0 if (max_diff_values['bus_va_degree'] < 100.0) else max_diff_values['bus_va_degree'])
                        logger.info('voltage_angles could be calculated.')
                    except pp.LoadflowNotConverged:
                        logger.error('The pandapower powerflow does not converge.')
        elif (pf_type == 'rundcpp'):
            try:
                pp.rundcpp(net, trafo_model='pi')
            except pp.LoadflowNotConverged:
                logger.error('The pandapower dc powerflow does not converge.')
        elif (pf_type == 'runopp'):
            try:
                pp.runopp(net, init='flat', calculate_voltage_angles=True)
            except pp.OPFNotConverged:
                try:
                    pp.runopp(net, init='pf', calculate_voltage_angles=True)
                except (pp.OPFNotConverged, pp.LoadflowNotConverged, KeyError):
                    try:
                        pp.runopp(net, init='flat', calculate_voltage_angles=False)
                        logger.info('voltage_angles could be calculated.')
                        if ('bus_va_degree' in max_diff_values.keys()):
                            max_diff_values['bus_va_degree'] = (100.0 if (max_diff_values['bus_va_degree'] < 100.0) else max_diff_values['bus_va_degree'])
                    except pp.OPFNotConverged:
                        try:
                            pp.runopp(net, init='pf', calculate_voltage_angles=False)
                            if ('bus_va_degree' in max_diff_values.keys()):
                                max_diff_values['bus_va_degree'] = (100.0 if (max_diff_values['bus_va_degree'] < 100.0) else max_diff_values['bus_va_degree'])
                            logger.info('voltage_angles could be calculated.')
                        except (pp.OPFNotConverged, pp.LoadflowNotConverged, KeyError):
                            logger.error('The pandapower optimal powerflow does not converge.')
        elif (pf_type == 'rundcopp'):
            try:
                pp.rundcopp(net)
            except pp.LoadflowNotConverged:
                logger.error('The pandapower dc optimal powerflow does not converge.')
        else:
            raise ValueError(('The pf_type %s is unknown' % pf_type))
    if (not ppc_success):
        return False
    if ('opp' in pf_type):
        if (not net.OPF_converged):
            return
    elif (not net.converged):
        return False
    ppc_res = dict.fromkeys(ppc_elms)
    ppc_res['branch'] = ppc_net['branch'][:, 13:17]
    ppc_res['bus'] = ppc_net['bus'][:, 7:9]
    ppc_res['gen'] = ppc_net['gen'][:, 1:3]
    pp_res = dict.fromkeys(ppc_elms)
    pp_res['bus'] = array(net.res_bus.sort_index()[['vm_pu', 'va_degree']])
    pp_res['gen'] = zeros([1, 2])
    if (len(ppc_net['gen'].shape) == 1):
        ppc_net['gen'] = array(ppc_net['gen'], ndmin=2)
    GENS = DataFrame(ppc_net['gen'][:, [0]].astype(int))
    GEN_uniq = GENS.drop_duplicates()
    already_used_gen = Series(zeros(GEN_uniq.shape[0]).astype(int), index=[int(v) for v in GEN_uniq.values])
    change_q_compare = []
    for (i, j) in GENS.iterrows():
        (current_bus_type, current_bus_idx, same_bus_gen_idx, first_same_bus_in_service_gen_idx, last_same_bus_in_service_gen_idx) = _gen_bus_info(ppc_net, i)
        if ((current_bus_type == 3) and (i == first_same_bus_in_service_gen_idx)):
            pp_res['gen'] = append(pp_res['gen'], array(net.res_ext_grid[(net.ext_grid.bus == current_bus_idx)][['p_mw', 'q_mvar']]).reshape((1, 2)), 0)
        elif ((current_bus_type == 2) and (i == first_same_bus_in_service_gen_idx)):
            pp_res['gen'] = append(pp_res['gen'], array(net.res_gen[(net.gen.bus == current_bus_idx)][['p_mw', 'q_mvar']]).reshape((1, 2)), 0)
        else:
            pp_res['gen'] = append(pp_res['gen'], array(net.res_sgen[(net.sgen.bus == current_bus_idx)][['p_mw', 'q_mvar']])[already_used_gen.at[int(j)]].reshape((1, 2)), 0)
            already_used_gen.at[int(j)] += 1
            change_q_compare += [int(j)]
    pp_res['gen'] = pp_res['gen'][1:, :]
    pp_res['branch'] = zeros([1, 4])
    try:
        init1 = concat([net.line.from_bus, net.line.to_bus], axis=1, sort=True).drop_duplicates()
        init2 = concat([net.trafo.hv_bus, net.trafo.lv_bus], axis=1, sort=True).drop_duplicates()
    except TypeError:
        init1 = concat([net.line.from_bus, net.line.to_bus], axis=1).drop_duplicates()
        init2 = concat([net.trafo.hv_bus, net.trafo.lv_bus], axis=1).drop_duplicates()
    init1['hv_bus'] = nan
    init1['lv_bus'] = nan
    init2['from_bus'] = nan
    init2['to_bus'] = nan
    try:
        already_used_branches = concat([init1, init2], axis=0, sort=True)
    except TypeError:
        already_used_branches = concat([init1, init2], axis=0)
    already_used_branches['number'] = zeros([already_used_branches.shape[0], 1]).astype(int)
    BRANCHES = DataFrame(ppc_net['branch'][:, [0, 1, 8, 9]])
    for i in BRANCHES.index:
        from_bus = pp.get_element_index(net, 'bus', name=int(ppc_net['branch'][(i, 0)]))
        to_bus = pp.get_element_index(net, 'bus', name=int(ppc_net['branch'][(i, 1)]))
        from_vn_kv = ppc_net['bus'][(from_bus, 9)]
        to_vn_kv = ppc_net['bus'][(to_bus, 9)]
        ratio = BRANCHES[2].at[i]
        angle = BRANCHES[3].at[i]
        if (((from_vn_kv == to_vn_kv) & ((ratio == 0) | (ratio == 1))) & (angle == 0)):
            pp_res['branch'] = append(pp_res['branch'], array(net.res_line[((net.line.from_bus == from_bus) & (net.line.to_bus == to_bus))][['p_from_mw', 'q_from_mvar', 'p_to_mw', 'q_to_mvar']])[int(already_used_branches.number.loc[((already_used_branches.from_bus == from_bus) & (already_used_branches.to_bus == to_bus))].values)].reshape(1, 4), 0)
            already_used_branches.number.loc[((already_used_branches.from_bus == from_bus) & (already_used_branches.to_bus == to_bus))] += 1
        elif (from_vn_kv >= to_vn_kv):
            pp_res['branch'] = append(pp_res['branch'], array(net.res_trafo[((net.trafo.hv_bus == from_bus) & (net.trafo.lv_bus == to_bus))][['p_hv_mw', 'q_hv_mvar', 'p_lv_mw', 'q_lv_mvar']])[int(already_used_branches.number.loc[((already_used_branches.hv_bus == from_bus) & (already_used_branches.lv_bus == to_bus))].values)].reshape(1, 4), 0)
            already_used_branches.number.loc[((already_used_branches.hv_bus == from_bus) & (already_used_branches.lv_bus == to_bus))] += 1
        else:
            pp_res['branch'] = append(pp_res['branch'], array(net.res_trafo[((net.trafo.hv_bus == to_bus) & (net.trafo.lv_bus == from_bus))][['p_lv_mw', 'q_lv_mvar', 'p_hv_mw', 'q_hv_mvar']])[int(already_used_branches.number.loc[((already_used_branches.hv_bus == to_bus) & (already_used_branches.lv_bus == from_bus))].values)].reshape(1, 4), 0)
            already_used_branches.number.loc[((already_used_branches.hv_bus == to_bus) & (already_used_branches.lv_bus == from_bus))] += 1
    pp_res['branch'] = pp_res['branch'][1:, :]
    diff_res = dict.fromkeys(ppc_elms)
    diff_res['bus'] = (ppc_res['bus'] - pp_res['bus'])
    diff_res['bus'][:, 1] -= diff_res['bus'][(0, 1)]
    diff_res['branch'] = (ppc_res['branch'] - pp_res['branch'])
    diff_res['gen'] = (ppc_res['gen'] - pp_res['gen'])
    for i in GEN_uniq.loc[GEN_uniq[0].isin(change_q_compare)].index:
        next_is = GEN_uniq.index[(GEN_uniq.index > i)]
        if (len(next_is) > 0):
            next_i = next_is[0]
        else:
            next_i = (GENS.index[(- 1)] + 1)
        if ((next_i - i) > 1):
            diff_res['gen'][i:next_i, 1] = sum(diff_res['gen'][i:next_i, 1])
    logger.debug(('Maximum voltage magnitude difference between pypower and pandapower: %.2e pu' % max_(abs(diff_res['bus'][:, 0]))))
    logger.debug(('Maximum voltage angle difference between pypower and pandapower: %.2e degree' % max_(abs(diff_res['bus'][:, 1]))))
    logger.debug(('Maximum branch flow active power difference between pypower and pandapower: %.2e MW' % max_(abs(diff_res['branch'][:, [0, 2]]))))
    logger.debug(('Maximum branch flow reactive power difference between pypower and pandapower: %.2e MVAr' % max_(abs(diff_res['branch'][:, [1, 3]]))))
    logger.debug(('Maximum active power generation difference between pypower and pandapower: %.2e MW' % max_(abs(diff_res['gen'][:, 0]))))
    logger.debug(('Maximum reactive power generation difference between pypower and pandapower: %.2e MVAr' % max_(abs(diff_res['gen'][:, 1]))))
    if (_validate_diff_res(diff_res, {'bus_vm_pu': 0.001, 'bus_va_degree': 0.001, 'branch_p_mw': 1e-06, 'branch_q_mvar': 1e-06}) and (max_(abs(diff_res['gen'])) > 0.1).any()):
        logger.debug('The active/reactive power generation difference possibly results because of a pypower error. Please validate the results via pypower loadflow.')
    if isinstance(max_diff_values, dict):
        return _validate_diff_res(diff_res, max_diff_values)
    else:
        logger.debug("'max_diff_values' must be a dict.")
This function validates the pypower case files to pandapower net structure conversion via a     comparison of loadflow calculation results. (Hence the opf cost conversion is not validated.)

INPUT:

    **ppc_net** - The pypower case file, which must already contain the pypower powerflow
        results or pypower must be importable.

    **net** - The pandapower network.

OPTIONAL:

    **pf_type** ("runpp", string) - Type of validated power flow. Possible are ("runpp",
        "rundcpp", "runopp", "rundcopp")

    **max_diff_values** - Dict of maximal allowed difference values. The keys must be
    'vm_pu', 'va_degree', 'p_branch_mw', 'q_branch_mvar', 'p_gen_mw' and 'q_gen_mvar' and
    the values floats.

    **run** (True, bool or list of two bools) - changing the value to False avoids trying to run
        (optimal) loadflows. Giving a list of two bools addresses first pypower and second
        pandapower.

OUTPUT:

    **conversion_success** - conversion_success is returned as False if pypower or pandapower
    cannot calculate a powerflow or if the maximum difference values (max_diff_values )
    cannot be hold.

EXAMPLE:

    import pandapower.converter as pc

    net = cv.from_ppc(ppc_net, f_hz=50)

    conversion_success = cv.validate_from_ppc(ppc_net, net)

NOTE:

    The user has to take care that the loadflow results already are included in the provided         ppc_net or pypower is importable.
def validate_from_ppc(ppc_net, net, pf_type='runpp', max_diff_values={'bus_vm_pu': 1e-06, 'bus_va_degree': 1e-05, 'branch_p_mw': 1e-06, 'branch_q_mvar': 1e-06, 'gen_p_mw': 1e-06, 'gen_q_mvar': 1e-06}, run=True):
    '\n    This function validates the pypower case files to pandapower net structure conversion via a     comparison of loadflow calculation results. (Hence the opf cost conversion is not validated.)\n\n    INPUT:\n\n        **ppc_net** - The pypower case file, which must already contain the pypower powerflow\n            results or pypower must be importable.\n\n        **net** - The pandapower network.\n\n    OPTIONAL:\n\n        **pf_type** ("runpp", string) - Type of validated power flow. Possible are ("runpp",\n            "rundcpp", "runopp", "rundcopp")\n\n        **max_diff_values** - Dict of maximal allowed difference values. The keys must be\n        \'vm_pu\', \'va_degree\', \'p_branch_mw\', \'q_branch_mvar\', \'p_gen_mw\' and \'q_gen_mvar\' and\n        the values floats.\n\n        **run** (True, bool or list of two bools) - changing the value to False avoids trying to run\n            (optimal) loadflows. Giving a list of two bools addresses first pypower and second\n            pandapower.\n\n    OUTPUT:\n\n        **conversion_success** - conversion_success is returned as False if pypower or pandapower\n        cannot calculate a powerflow or if the maximum difference values (max_diff_values )\n        cannot be hold.\n\n    EXAMPLE:\n\n        import pandapower.converter as pc\n\n        net = cv.from_ppc(ppc_net, f_hz=50)\n\n        conversion_success = cv.validate_from_ppc(ppc_net, net)\n\n    NOTE:\n\n        The user has to take care that the loadflow results already are included in the provided         ppc_net or pypower is importable.\n    '
    if ('opp' in pf_type):
        if (not (len(net.polynomial_cost) | len(net.piecewise_linear_cost))):
            if ('gencost' in ppc_net):
                if (not len(ppc_net['gencost'])):
                    logger.debug('ppc and pandapower net do not include cost information.')
                    return True
                else:
                    logger.error('The pandapower net does not include cost information.')
                    return False
            else:
                logger.debug('ppc and pandapower net do not include cost information.')
                return True
    run = ([run, run] if isinstance(run, bool) else run)
    if (pypower_import and run[0]):
        try:
            if (pf_type == 'runpp'):
                ppc_net = runpf.runpf(ppc_net, ppopt)[0]
            elif (pf_type == 'rundcpp'):
                ppc_net = rundcpf.rundcpf(ppc_net, ppopt)[0]
            elif (pf_type == 'runopp'):
                ppc_net = runopf.runopf(ppc_net, ppopt)
            elif (pf_type == 'rundcopp'):
                ppc_net = rundcopf.rundcopf(ppc_net, ppopt)
            else:
                raise ValueError(('The pf_type %s is unknown' % pf_type))
        except:
            logger.debug('The pypower run did not work.')
    ppc_success = True
    if ('success' in ppc_net.keys()):
        if (ppc_net['success'] != 1):
            ppc_success = False
            logger.error(('The given ppc data indicates an unsuccessful pypower powerflow: ' + "'ppc_net['success'] != 1'"))
    if (ppc_net['branch'].shape[1] < 17):
        ppc_success = False
        logger.error('The shape of given ppc data indicates missing pypower powerflow results.')
    if run[1]:
        if (pf_type == 'runpp'):
            try:
                pp.runpp(net, init='dc', calculate_voltage_angles=True, trafo_model='pi')
            except pp.LoadflowNotConverged:
                try:
                    pp.runpp(net, calculate_voltage_angles=True, init='flat', trafo_model='pi')
                except pp.LoadflowNotConverged:
                    try:
                        pp.runpp(net, trafo_model='pi', calculate_voltage_angles=False)
                        if ('bus_va_degree' in max_diff_values.keys()):
                            max_diff_values['bus_va_degree'] = (100.0 if (max_diff_values['bus_va_degree'] < 100.0) else max_diff_values['bus_va_degree'])
                        logger.info('voltage_angles could be calculated.')
                    except pp.LoadflowNotConverged:
                        logger.error('The pandapower powerflow does not converge.')
        elif (pf_type == 'rundcpp'):
            try:
                pp.rundcpp(net, trafo_model='pi')
            except pp.LoadflowNotConverged:
                logger.error('The pandapower dc powerflow does not converge.')
        elif (pf_type == 'runopp'):
            try:
                pp.runopp(net, init='flat', calculate_voltage_angles=True)
            except pp.OPFNotConverged:
                try:
                    pp.runopp(net, init='pf', calculate_voltage_angles=True)
                except (pp.OPFNotConverged, pp.LoadflowNotConverged, KeyError):
                    try:
                        pp.runopp(net, init='flat', calculate_voltage_angles=False)
                        logger.info('voltage_angles could be calculated.')
                        if ('bus_va_degree' in max_diff_values.keys()):
                            max_diff_values['bus_va_degree'] = (100.0 if (max_diff_values['bus_va_degree'] < 100.0) else max_diff_values['bus_va_degree'])
                    except pp.OPFNotConverged:
                        try:
                            pp.runopp(net, init='pf', calculate_voltage_angles=False)
                            if ('bus_va_degree' in max_diff_values.keys()):
                                max_diff_values['bus_va_degree'] = (100.0 if (max_diff_values['bus_va_degree'] < 100.0) else max_diff_values['bus_va_degree'])
                            logger.info('voltage_angles could be calculated.')
                        except (pp.OPFNotConverged, pp.LoadflowNotConverged, KeyError):
                            logger.error('The pandapower optimal powerflow does not converge.')
        elif (pf_type == 'rundcopp'):
            try:
                pp.rundcopp(net)
            except pp.LoadflowNotConverged:
                logger.error('The pandapower dc optimal powerflow does not converge.')
        else:
            raise ValueError(('The pf_type %s is unknown' % pf_type))
    if (not ppc_success):
        return False
    if ('opp' in pf_type):
        if (not net.OPF_converged):
            return
    elif (not net.converged):
        return False
    ppc_res = dict.fromkeys(ppc_elms)
    ppc_res['branch'] = ppc_net['branch'][:, 13:17]
    ppc_res['bus'] = ppc_net['bus'][:, 7:9]
    ppc_res['gen'] = ppc_net['gen'][:, 1:3]
    pp_res = dict.fromkeys(ppc_elms)
    pp_res['bus'] = array(net.res_bus.sort_index()[['vm_pu', 'va_degree']])
    pp_res['gen'] = zeros([1, 2])
    if (len(ppc_net['gen'].shape) == 1):
        ppc_net['gen'] = array(ppc_net['gen'], ndmin=2)
    GENS = DataFrame(ppc_net['gen'][:, [0]].astype(int))
    GEN_uniq = GENS.drop_duplicates()
    already_used_gen = Series(zeros(GEN_uniq.shape[0]).astype(int), index=[int(v) for v in GEN_uniq.values])
    change_q_compare = []
    for (i, j) in GENS.iterrows():
        (current_bus_type, current_bus_idx, same_bus_gen_idx, first_same_bus_in_service_gen_idx, last_same_bus_in_service_gen_idx) = _gen_bus_info(ppc_net, i)
        if ((current_bus_type == 3) and (i == first_same_bus_in_service_gen_idx)):
            pp_res['gen'] = append(pp_res['gen'], array(net.res_ext_grid[(net.ext_grid.bus == current_bus_idx)][['p_mw', 'q_mvar']]).reshape((1, 2)), 0)
        elif ((current_bus_type == 2) and (i == first_same_bus_in_service_gen_idx)):
            pp_res['gen'] = append(pp_res['gen'], array(net.res_gen[(net.gen.bus == current_bus_idx)][['p_mw', 'q_mvar']]).reshape((1, 2)), 0)
        else:
            pp_res['gen'] = append(pp_res['gen'], array(net.res_sgen[(net.sgen.bus == current_bus_idx)][['p_mw', 'q_mvar']])[already_used_gen.at[int(j)]].reshape((1, 2)), 0)
            already_used_gen.at[int(j)] += 1
            change_q_compare += [int(j)]
    pp_res['gen'] = pp_res['gen'][1:, :]
    pp_res['branch'] = zeros([1, 4])
    try:
        init1 = concat([net.line.from_bus, net.line.to_bus], axis=1, sort=True).drop_duplicates()
        init2 = concat([net.trafo.hv_bus, net.trafo.lv_bus], axis=1, sort=True).drop_duplicates()
    except TypeError:
        init1 = concat([net.line.from_bus, net.line.to_bus], axis=1).drop_duplicates()
        init2 = concat([net.trafo.hv_bus, net.trafo.lv_bus], axis=1).drop_duplicates()
    init1['hv_bus'] = nan
    init1['lv_bus'] = nan
    init2['from_bus'] = nan
    init2['to_bus'] = nan
    try:
        already_used_branches = concat([init1, init2], axis=0, sort=True)
    except TypeError:
        already_used_branches = concat([init1, init2], axis=0)
    already_used_branches['number'] = zeros([already_used_branches.shape[0], 1]).astype(int)
    BRANCHES = DataFrame(ppc_net['branch'][:, [0, 1, 8, 9]])
    for i in BRANCHES.index:
        from_bus = pp.get_element_index(net, 'bus', name=int(ppc_net['branch'][(i, 0)]))
        to_bus = pp.get_element_index(net, 'bus', name=int(ppc_net['branch'][(i, 1)]))
        from_vn_kv = ppc_net['bus'][(from_bus, 9)]
        to_vn_kv = ppc_net['bus'][(to_bus, 9)]
        ratio = BRANCHES[2].at[i]
        angle = BRANCHES[3].at[i]
        if (((from_vn_kv == to_vn_kv) & ((ratio == 0) | (ratio == 1))) & (angle == 0)):
            pp_res['branch'] = append(pp_res['branch'], array(net.res_line[((net.line.from_bus == from_bus) & (net.line.to_bus == to_bus))][['p_from_mw', 'q_from_mvar', 'p_to_mw', 'q_to_mvar']])[int(already_used_branches.number.loc[((already_used_branches.from_bus == from_bus) & (already_used_branches.to_bus == to_bus))].values)].reshape(1, 4), 0)
            already_used_branches.number.loc[((already_used_branches.from_bus == from_bus) & (already_used_branches.to_bus == to_bus))] += 1
        elif (from_vn_kv >= to_vn_kv):
            pp_res['branch'] = append(pp_res['branch'], array(net.res_trafo[((net.trafo.hv_bus == from_bus) & (net.trafo.lv_bus == to_bus))][['p_hv_mw', 'q_hv_mvar', 'p_lv_mw', 'q_lv_mvar']])[int(already_used_branches.number.loc[((already_used_branches.hv_bus == from_bus) & (already_used_branches.lv_bus == to_bus))].values)].reshape(1, 4), 0)
            already_used_branches.number.loc[((already_used_branches.hv_bus == from_bus) & (already_used_branches.lv_bus == to_bus))] += 1
        else:
            pp_res['branch'] = append(pp_res['branch'], array(net.res_trafo[((net.trafo.hv_bus == to_bus) & (net.trafo.lv_bus == from_bus))][['p_lv_mw', 'q_lv_mvar', 'p_hv_mw', 'q_hv_mvar']])[int(already_used_branches.number.loc[((already_used_branches.hv_bus == to_bus) & (already_used_branches.lv_bus == from_bus))].values)].reshape(1, 4), 0)
            already_used_branches.number.loc[((already_used_branches.hv_bus == to_bus) & (already_used_branches.lv_bus == from_bus))] += 1
    pp_res['branch'] = pp_res['branch'][1:, :]
    diff_res = dict.fromkeys(ppc_elms)
    diff_res['bus'] = (ppc_res['bus'] - pp_res['bus'])
    diff_res['bus'][:, 1] -= diff_res['bus'][(0, 1)]
    diff_res['branch'] = (ppc_res['branch'] - pp_res['branch'])
    diff_res['gen'] = (ppc_res['gen'] - pp_res['gen'])
    for i in GEN_uniq.loc[GEN_uniq[0].isin(change_q_compare)].index:
        next_is = GEN_uniq.index[(GEN_uniq.index > i)]
        if (len(next_is) > 0):
            next_i = next_is[0]
        else:
            next_i = (GENS.index[(- 1)] + 1)
        if ((next_i - i) > 1):
            diff_res['gen'][i:next_i, 1] = sum(diff_res['gen'][i:next_i, 1])
    logger.debug(('Maximum voltage magnitude difference between pypower and pandapower: %.2e pu' % max_(abs(diff_res['bus'][:, 0]))))
    logger.debug(('Maximum voltage angle difference between pypower and pandapower: %.2e degree' % max_(abs(diff_res['bus'][:, 1]))))
    logger.debug(('Maximum branch flow active power difference between pypower and pandapower: %.2e MW' % max_(abs(diff_res['branch'][:, [0, 2]]))))
    logger.debug(('Maximum branch flow reactive power difference between pypower and pandapower: %.2e MVAr' % max_(abs(diff_res['branch'][:, [1, 3]]))))
    logger.debug(('Maximum active power generation difference between pypower and pandapower: %.2e MW' % max_(abs(diff_res['gen'][:, 0]))))
    logger.debug(('Maximum reactive power generation difference between pypower and pandapower: %.2e MVAr' % max_(abs(diff_res['gen'][:, 1]))))
    if (_validate_diff_res(diff_res, {'bus_vm_pu': 0.001, 'bus_va_degree': 0.001, 'branch_p_mw': 1e-06, 'branch_q_mvar': 1e-06}) and (max_(abs(diff_res['gen'])) > 0.1).any()):
        logger.debug('The active/reactive power generation difference possibly results because of a pypower error. Please validate the results via pypower loadflow.')
    if isinstance(max_diff_values, dict):
        return _validate_diff_res(diff_res, max_diff_values)
    else:
        logger.debug("'max_diff_values' must be a dict.")