From fe584719f410f9973e5c7b48c4f3c65692c2a242 Mon Sep 17 00:00:00 2001 From: Vincent Luczkow Date: Thu, 18 Aug 2022 00:28:04 -0700 Subject: [PATCH] Location is attached to sampling_event. ObservationWrapper has a custom insert function. Closes #68, closes #79 --- aukpy/db.py | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/aukpy/db.py b/aukpy/db.py index c73342f..b9f2c64 100644 --- a/aukpy/db.py +++ b/aukpy/db.py @@ -421,26 +421,19 @@ def df_processing(cls, df: pd.DataFrame) -> pd.DataFrame: return df - # @classmethod - # def insert( - # cls, - # df: pd.DataFrame, - # db: sqlite3.Connection, - # cache: Optional[Dict[Any, int]] = None, ) -> Tuple[pd.DataFrame, Dict[Any, int]]: - # # Table specific preprocessing - # if cache is None: - # cache = {} - # # sub_frame = cls.df_processing(df.loc[:, list(cls.columns)]) - # # max_id = max_id if max_id is not None else 0 - # # TODO: Optimization: Sort and drop_duplicates is probably faster. - # # groups_to_idx = sub_frame.fillna("").groupby(list(cls.unique_columns)).groups - # # new_idx = {g: idx[0] for g, idx in groups_to_idx.items() if g not in cache} - # # new_values = [sub_frame.loc[idx].tolist() for idx in new_idx.values()] - - # import pdb - # pdb.set_trace() - # # db.executemany(cls.insert_query, new_values) - # return df, cache + @classmethod + def insert( + cls, + df: pd.DataFrame, + db: sqlite3.Connection, + cache: Optional[Dict[Any, int]] = None, + ) -> Tuple[pd.DataFrame, Dict[Any, int]]: + # Table specific preprocessing + if cache is None: + cache = {} + sub_frame = cls.df_processing(df.loc[:, list(cls.columns)]) + sub_frame.to_sql("observation", con=db, if_exists="append", index=False) + return df, cache WRAPPERS = (