1717from attrs import define
1818
1919from pandas_openscm .db .interfaces import OpenSCMDBDataBackend
20+ from pandas_openscm .db .path_handling import DBPath
2021from pandas_openscm .index_manipulation import (
2122 unify_index_levels_check_index_types ,
2223 update_index_from_candidates ,
@@ -180,7 +181,8 @@ def make_move_plan(
180181 index_start : pd .DataFrame ,
181182 file_map_start : pd .Series [Path ], # type: ignore # pandas confused about ability to support Path
182183 data_to_write : pd .DataFrame ,
183- get_new_data_file_path : Callable [[int ], Path ],
184+ get_new_data_file_path : Callable [[int ], DBPath ],
185+ db_dir : Path ,
184186) -> MovePlan :
185187 """
186188 Make a plan for moving data around to make room for new data
@@ -196,6 +198,12 @@ def make_move_plan(
196198 data_to_write
197199 Data that is going to be written in the database
198200
201+ get_new_data_file_path
202+ Callable which, given an integer, returns the path info for the new data file
203+
204+ db_dir
205+ Database directory
206+
199207 Returns
200208 -------
201209 :
@@ -229,7 +237,7 @@ def make_move_plan(
229237 # (would be even more efficient to just update the file IDs,
230238 # but that would create a coupling I can't get my head around right now).
231239 delete_file_ids = full_overwrite .index [full_overwrite ]
232- delete_paths = file_map_start .loc [delete_file_ids ]
240+ delete_paths = ( db_dir / v for v in file_map_start .loc [delete_file_ids ])
233241 moved_index = index_start [~ index_start ["file_id" ].isin (delete_file_ids )]
234242 file_map_out = file_map_start .loc [moved_index ["file_id" ].unique ()]
235243
@@ -246,7 +254,7 @@ def make_move_plan(
246254 full_overwrite_file_ids = full_overwrite .index [full_overwrite ]
247255 partial_overwrite_file_ids = partial_overwrite .index [partial_overwrite ]
248256 file_ids_to_delete = np .union1d (full_overwrite_file_ids , partial_overwrite_file_ids )
249- delete_paths = file_map_start .loc [file_ids_to_delete ]
257+ delete_paths = ( db_dir / v for v in file_map_start .loc [file_ids_to_delete ])
250258
251259 file_id_map = {}
252260 max_file_id_start = file_map_start .index .max ()
@@ -259,12 +267,13 @@ def make_move_plan(
259267 ):
260268 new_file_id = max_file_id_start + 1 + increment
261269
262- file_map_out .loc [new_file_id ] = get_new_data_file_path (new_file_id )
270+ new_db_path = get_new_data_file_path (new_file_id )
271+ file_map_out .loc [new_file_id ] = new_db_path .rel_db
263272
264273 rewrite_actions_l .append (
265274 ReWriteAction (
266- from_file = file_map_start .loc [file_id_old ],
267- to_file = file_map_out . loc [ new_file_id ] ,
275+ from_file = db_dir / file_map_start .loc [file_id_old ],
276+ to_file = new_db_path . abs ,
268277 locator = fiddf .index .droplevel ("file_id" ),
269278 )
270279 )
0 commit comments