def apply_field_values(field_values: Union[dict, list, tuple, Future], priceable_inst: Priceable, future: Optional[Future] = None): if isinstance(field_values, str): raise RuntimeError(field_values) if isinstance(field_values, Future): field_values = field_values.result() if isinstance(field_values, (list, tuple)): if len(field_values) == 1: field_values = field_values[0] else: date_result = {} for fv in field_values: date = dt.date.fromtimestamp(fv['date'] / 1e9) as_of = next( a for a in resolution_key.pricing_market_data_as_of if date == a.pricing_date) date_key = resolution_key.clone( pricing_market_data_as_of=as_of) date_result[date] = apply_field_values( fv, priceable_inst, date_key) future.set_result(date_result) return field_values = { field: value_mappings.get(value, value) for field, value in field_values.items() if inflection.underscore(field) in priceable_inst.properties() and value not in invalid_defaults } if in_place and not future: priceable_inst.unresolved = copy.copy(priceable_inst) for field, value in field_values.items(): setattr(priceable_inst, field, value) priceable_inst.resolution_key = resolution_key else: new_inst = priceable_inst._from_dict(field_values) new_inst.unresolved = priceable_inst new_inst.resolution_key = resolution_key if future: future.set_result(new_inst) else: return new_inst
def apply_field_values( field_values: Union[dict, list, tuple, Future], priceable_inst: Priceable, resolution_info: dict, future: Optional[Future] = None ): if isinstance(field_values, str): raise RuntimeError(field_values) if isinstance(field_values, Future): field_values = field_values.result() if isinstance(field_values, (list, tuple)): if len(field_values) == 1: field_values = field_values[0] else: res = {} for fv in field_values: date = dt.date.fromtimestamp(fv['date'] / 1e9) date_resolution_info = { 'pricing_date': date, 'market_data_as_of': fv['date'], 'market_data_location': resolution_info['market_data_location'] } res[date] = apply_field_values(fv, priceable_inst, date_resolution_info) future.set_result(res) return field_values = {field: value_mappings.get(value, value) for field, value in field_values.items() if inflection.underscore(field) in priceable_inst.properties() and value not in invalid_defaults} if in_place and not future: priceable_inst.unresolved = copy.copy(priceable_inst) for field, value in field_values.items(): setattr(priceable_inst, field, value) priceable_inst._resolution_info = resolution_info else: new_inst = priceable_inst._from_dict(field_values) new_inst.unresolved = priceable_inst new_inst._resolution_info = resolution_info if future: future.set_result(new_inst) else: return new_inst
def apply_field_values(field_values: Union[dict, list, tuple, Future], priceable_inst: Priceable, future: Optional[Future] = None): if isinstance(field_values, str): raise RuntimeError(field_values) if isinstance(field_values, Future): field_values = field_values.result() if isinstance(field_values, (list, tuple)): if len(field_values) == 1: field_values = field_values[0] else: future.set_result({ dt.date.fromtimestamp(fv['date'] / 1e9): apply_field_values(fv, priceable_inst) for fv in field_values }) return field_values = { field: value_mappings.get(value, value) for field, value in field_values.items() if field in priceable_inst.properties() and value not in invalid_defaults } if in_place and not future: for field, value in field_values.items(): setattr(priceable_inst, field, value) priceable_inst._resolved = True else: new_inst = priceable_inst._from_dict(field_values) new_inst._resolved = True if future: future.set_result(new_inst) else: return new_inst