@@ -147,7 +147,7 @@ def write(
147147 return p
148148
149149
150- def do_one (leaf : Extents , config : ShatterConfig , storage : Storage ) -> db . Bag :
150+ def do_one (leaf : Extents , config : ShatterConfig , storage : Storage ) -> pd . DataFrame :
151151 """
152152 Create dask bags and the order of operations.
153153
@@ -160,18 +160,17 @@ def do_one(leaf: Extents, config: ShatterConfig, storage: Storage) -> db.Bag:
160160 # remove any extents that have already been done, only skip if full overlap
161161 if config .mbr :
162162 if not all (leaf .disjoint_by_mbr (m ) for m in config .mbr ):
163- return 0
163+ return None
164164 points = get_data (leaf , config .filename , storage )
165165 if points .empty :
166- return 0
166+ return None
167167 listed_data = agg_list (points , config .time_slot )
168168 metric_data = run_graph (points , storage .get_metrics ())
169169 joined_data = join (listed_data , metric_data )
170- point_count = write (joined_data , storage , config .date )
171170
172- del points , joined_data , listed_data , metric_data
171+ del points , listed_data , metric_data
173172
174- return point_count
173+ return joined_data
175174
176175
177176Leaves = Generator [Extents , None , None ]
@@ -189,34 +188,41 @@ def run(leaves: Leaves, config: ShatterConfig, storage: Storage) -> int:
189188
190189 start_time = int (datetime .now ().timestamp ()* 1000 )
191190 dc = get_client ()
191+
192+ joined_dfs = []
192193 failures = []
194+
193195 if dc is not None :
194196 # TODO make this a batched operation of like 1000 tasks at a time?
195197 # itertools batched would limit us to >python3.12
196198 futures = [dc .submit (do_one , leaf = leaf , config = config , storage = storage ) for leaf in leaves ]
197199 res = as_completed (futures , with_results = True , raise_errors = False )
198- for future , pc in res :
200+ for future , df in res :
199201 if future .status == 'error' :
200202 failures .append (pc )
201203 continue
202204
203- if pc is None :
204- continue
205- if isinstance (pc , int ):
206- config .point_count = config .point_count + pc
207- del pc
205+ if df is not None :
206+ joined_dfs .append (df )
208207
209208 # TODO write out errors to errors storage path?
210209
211210 else :
212211 processes = [delayed (do_one )(leaf , config , storage ) for leaf in leaves ]
213212 # Handle non-distributed dask scenarios
214213 results = compute (* processes )
215- pcs = [
216- possible_pc for possible_pc in results if possible_pc is not None
217- ]
218- pc = sum (pcs )
214+
215+ joined_dfs = [df for df in results if df is not None ]
216+
217+ if joined_dfs :
218+ final_df = pd .concat (joined_dfs , ignore_index = True )
219+ pc = write (final_df , storage , config .date )
219220 config .point_count = config .point_count + pc
221+
222+ del final_df , joined_dfs
223+ else :
224+ config .point_count = 0
225+
220226 end_time = int (datetime .now ().timestamp ()* 1000 )
221227 storage .consolidate (timestamp = (start_time , end_time ))
222228
0 commit comments