From cbbd71f4962492a57020f3d7f810f185af272ff8 Mon Sep 17 00:00:00 2001 From: Michael Hoss Date: Tue, 30 Jan 2024 18:10:02 +0100 Subject: [PATCH] tidy up and fix bug of messing up an empty MultiIndex --- python-sdk/nuscenes/eval/tracking/mot.py | 40 ++---------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/python-sdk/nuscenes/eval/tracking/mot.py b/python-sdk/nuscenes/eval/tracking/mot.py index b2d39ebd..53b813f3 100644 --- a/python-sdk/nuscenes/eval/tracking/mot.py +++ b/python-sdk/nuscenes/eval/tracking/mot.py @@ -57,7 +57,6 @@ def new_event_dataframe_with_data(indices, events): ] idx = pd.MultiIndex.from_arrays( - # TODO What types are the indices FrameId and Event? string or int? [indices[field] for field in _INDEX_FIELDS], names=_INDEX_FIELDS) df = pd.concat(series, axis=1) @@ -129,46 +128,11 @@ def merge_event_dataframes(dfs, update_frame_indices=True, update_oids=True, upd # Update index if update_frame_indices: # pylint: disable=cell-var-from-loop - # TODO TypeError: can only concatenate tuple (not "int") to tuple - # This is likely because we have a multi-index dataframe r here (see new_event_dataframe()) - # See also https://stackoverflow.com/questions/39080555/pandas-get-level-values-for-multiple-columns - # Playground code: https://onecompiler.com/python/422kn8tev - """ - - import pandas as pd - - a={"gk":[15,12,13,22,32,12],"mk":[12,21,23,22,56,12], "sf": [1,2,3,4,5,5]} - df=pd.DataFrame(a) - - # B=df[df["mk"]>=21] - - # print(df) - # print(B) - - df = df.set_index(["gk", "sf"]) - - print(df) - - print("Experiment") - print(df.index.get_level_values(1)) - print("First argument of max") - print(df.index.get_level_values(0).max()) - print(df.index.get_level_values(0).max() +1) # the maximum value of the 0th index column incremented by 1 - print(df.index.get_level_values(1).max()) - print(df.index.get_level_values(1).max() +1) - print("Second argument of max") - print(df.index.get_level_values(0)) - print(df.index.get_level_values(0).unique()) - print(df.index.get_level_values(0).unique().shape) - print(df.index.get_level_values(0).unique().shape[0]) # number of unique values in the 0th index column - print("Final max evaluation") - print(max(df.index.get_level_values(0).max() +1,df.index.get_level_values(0).unique().shape[0])) - """ - next_frame_id = max(r.index.get_level_values(0).max() + 1, r.index.get_level_values(0).unique().shape[0]) if np.isnan(next_frame_id): next_frame_id = 0 - copy.index = copy.index.map(lambda x: (x[0] + next_frame_id, x[1])) + if not copy.index.empty: + copy.index = copy.index.map(lambda x: (x[0] + next_frame_id, x[1])) infos['frame_offset'] = next_frame_id # Update object / hypothesis ids