Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refacto: dataframe loop with itertuples to spot memory leak #238

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions quotaclimat/data_processing/mediatree/api_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,17 @@ async def get_and_save_api_data(exit_event):
try:
programs_for_this_day = get_programs_for_this_day(day, channel, df_programs)

for index, program in programs_for_this_day.iterrows():
start_epoch = program['start']
end_epoch = program['end']
channel_program = str(program['program_name'])
channel_program_type = str(program['program_type'])
for program in programs_for_this_day.itertuples(index=False):
start_epoch = program.start
end_epoch = program.end
channel_program = str(program.program_name)
channel_program_type = str(program.program_type)
logging.info(f"Querying API for {channel} - {channel_program} - {channel_program_type} - {start_epoch} - {end_epoch}")
df = extract_api_sub(token, channel, type_sub, start_epoch,end_epoch, channel_program,channel_program_type)
if(df is not None):
logging.debug(f"Memory df {df.memory_usage()}")
save_to_pg(df, keywords_table, conn)
del df
else:
logging.info("Nothing to save to Postgresql")
gc.collect()
Expand Down
Loading