I have a function that will be used under different modules. There are two functions that take different arguments but the function logic is similar. I am trying to unite func1 and func2 functions into one.
Is there a way I can use the python functionality to handle this case?
func1
def create_data_file_removed_duplicate_item(packing_data, output_dir, warehouse_name, date, model_type):
packing_data = packing_data.drop_duplicates(subset='item_id', keep="last")
# create non duplicate item data file
make_directory(output_dir)
file_name_for_non_duplicate \
= ap_conf.file_name_of_processed_data_non_duplicate_item\
.format(warehouse_name=warehouse_name, date=date, model_type=model_type)
file_path_for_non_duplicate = output_dir + file_name_for_non_duplicate
packing_data.to_csv(file_path_for_non_duplicate, sep="\t", header=False, index=False)
return file_path_for_non_duplicate
func2:
def create_data_file_without_duplicate_item(packing_data, output_dir, model_type):
packing_data = packing_data.drop_duplicates(subset='item_id', keep="last")
# create non-duplicate item data file
make_directory(output_dir)
file_name_for_non_duplicate \
= ap_conf.file_name_of_processed_data_aggregated_warehouse_non_duplicate_item \
.format(model_type=model_type)
file_path_for_non_duplicate = output_dir + file_name_for_non_duplicate
packing_data.to_csv(file_path_for_non_duplicate, sep="\t", header=False, index=False)
logger.info('data count after removing duplicates: ' + str(len(packing_data)))
return file_path_for_non_duplicate
warehouse_nameanddateto the end of the parameter list and make them optional. Then check if they are set inside the method. Something likecreate_data_file_without_duplicate_item(packing_data, output_dir, model_type, warehouse_name=None, date=None).