def merge_pyalgo_accdb(pyalgo, accdb): pyalgo = pyalgo.copy() pyalgo.columns = wio.flatten_columns(pyalgo.columns) merged = pd.concat((pyalgo, accdb), axis=1, keys=("pyalgo", "accdb")) merged.columns = wio.flatten_columns(merged.columns) return merged
def test_flatten_columns(): cols = pd.MultiIndex.from_tuples([("a", "aa"), ("b", "")], names=("gear", "item")) fcols = wio.flatten_columns(cols) infcols = wio.inflate_columns(fcols) assert cols.equals(infcols) assert cols.names == infcols.names with pytest.raises(AssertionError, match="MultiIndex?"): wio.inflate_columns(cols)
def is_more_low_powered_gears(cyc): cyc2 = cyc.copy() cyc2.columns = wio.inflate_columns(cyc2.columns) c22 = cyc2.iloc[1571:1579][["ok_p", "ok_max_n"]].dropna(axis=1, how="all") try: ## is there any row with all-low-p AND 2-or-more n-max-ok? bad_rows = (~c22["ok_p"].replace(-1, 0).astype("bool")).all(axis=1) & ( c22["ok_max_n"].replace(-1, 0).astype("bool").sum(axis=1) > 1) if bad_rows.any(): c22.columns = wio.flatten_columns(c22.columns) return ( list(bad_rows[bad_rows].index), pd.concat( (c22, cyc.iloc[1571:1579].loc[:, ["g_min", "g_max"]]), axis=1), ) except Exception as ex: print(ex)
def display_pyalgo_flags(pyalgo, accdb, props): flags = pyalgo.select_dtypes("int8").copy() flags.columns = wio.flatten_columns(flags.columns) pyalgo = pyalgo[["p_req", "p_avail"]].copy() pyalgo.columns = wio.flatten_columns(pyalgo.columns) grid(pd.concat((pyalgo, flags), axis=1))
def display_pyalgo(pyalgo, accdb, props): pyalgo.columns = wio.flatten_columns(pyalgo.columns) grid(pyalgo.drop("t", axis=1))
# veh_nums += [82, 88, 91, 99, 100, 101, 112, 113, 114] # # UNCOMMENT next line to FETCH new vehicles. p1, c1, p2, c2 = load_accdb_and_python_datasets() equivalent_series = [ ("v_orig", "V_cycle"), ("v_downscale", "v_target"), # ("a", "a_target"), ("P_tot_set", "p_req"), # ("P_max", "p_available"), ("g_max", "g_max0"), ("g_min", "g_min"), # ("gear", "gears"), # ("nc", "n"), ] c2.columns = wio.flatten_columns(c2.columns) cols1, cols2 = zip(*equivalent_series) cols1, cols2 = list(cols1), list(cols2) ## Concat props to col-aggregates & convert prop-cols to numerics cc1 = pd.concat((p1.infer_objects(), c1[cols1].abs().mean(level=0)), axis=1) cc2 = pd.concat((p2.infer_objects(), c2[cols2].abs().mean(level=0)), axis=1) equivalent_props = [ ("Description", None), ("vehicle_class", "wltc_class"), ("pmr_km", None), ("no_of_gears", None), ("f_dsc_req", "f_dsc"), ("v_max", "v_max"), ("n_vmax", "n_vmax"),