diff --git a/syscore/pandas/merge_data_keeping_past_data.py b/syscore/pandas/merge_data_keeping_past_data.py index 232437fe9f..ac5a11742a 100644 --- a/syscore/pandas/merge_data_keeping_past_data.py +++ b/syscore/pandas/merge_data_keeping_past_data.py @@ -57,6 +57,10 @@ class mergeStatus(Enum): NO_MERGE_DATE = named_object("No data") +class mergeError(Exception): + pass + + class mergingDataWithStatus(object): def __init__( self, diff --git a/sysdata/futures/futures_per_contract_prices.py b/sysdata/futures/futures_per_contract_prices.py index fb65b0fe98..83a9339084 100644 --- a/sysdata/futures/futures_per_contract_prices.py +++ b/sysdata/futures/futures_per_contract_prices.py @@ -1,7 +1,6 @@ from syscore.exceptions import missingData -from syscore.constants import failure from syscore.dateutils import Frequency, MIXED_FREQ -from syscore.pandas.merge_data_keeping_past_data import SPIKE_IN_DATA +from syscore.pandas.merge_data_keeping_past_data import SPIKE_IN_DATA, mergeError from sysdata.base_data import baseData @@ -383,7 +382,7 @@ def update_prices_at_frequency_for_contract( if rows_added < 0: new_log.critical("Can't remove prices something gone wrong!") - return failure + raise mergeError("Merged prices have fewer rows than old prices!") elif rows_added == 0: if len(old_prices) == 0: diff --git a/sysproduction/update_historical_prices.py b/sysproduction/update_historical_prices.py index fe6751369c..ea6d104495 100644 --- a/sysproduction/update_historical_prices.py +++ b/sysproduction/update_historical_prices.py @@ -10,7 +10,7 @@ from syscore.constants import arg_not_supplied, success, failure from syscore.exceptions import missingData -from syscore.pandas.merge_data_keeping_past_data import SPIKE_IN_DATA +from syscore.pandas.merge_data_keeping_past_data import SPIKE_IN_DATA, mergeError from syscore.dateutils import DAILY_PRICE_FREQ, Frequency from syscore.pandas.frequency import merge_data_with_different_freq @@ -432,22 +432,22 @@ def price_updating_or_errors( price_updater = updatePrices(data) - error_or_rows_added = price_updater.update_prices_at_frequency_for_contract( - contract_object=contract_object, - new_prices=new_prices_checked, - frequency=frequency, - check_for_spike=check_for_spike, - max_price_spike=cleaning_config.max_price_spike, - ) + try: + error_or_rows_added = price_updater.update_prices_at_frequency_for_contract( + contract_object=contract_object, + new_prices=new_prices_checked, + frequency=frequency, + check_for_spike=check_for_spike, + max_price_spike=cleaning_config.max_price_spike, + ) + except mergeError: + data.log.warning("Something went wrong when adding rows") + return failure if error_or_rows_added is SPIKE_IN_DATA: report_price_spike(data, contract_object) return failure - if error_or_rows_added is failure: - data.log.warning("Something went wrong when adding rows") - return failure - return error_or_rows_added